import * as React from "react"; import classNames from "classnames"; import { AriaListBoxOptions } from "react-aria"; import type { ComboBoxState, SelectState } from "react-stately"; import { Control, ControlInputProps, ControlNestedElementProps } from "../Control/Control"; import { DropdownListBox } from "./dropdown/DropdownListBox"; import styles from "./Picker.module.css"; export interface PickerManagedProps extends ControlNestedElementProps { controlState: SelectState | ComboBoxState; listBoxProps: AriaListBoxOptions; listBoxRef?: React.RefObject; children: React.ReactNode; } export interface PickerPublicProps extends ControlInputProps {} export interface PickerProps extends PickerPublicProps, PickerManagedProps {} export function Picker(props: PickerProps) { const { controlState, listBoxProps, listBoxRef, className, children } = props; const handleBlur = React.useCallback( (event: React.FocusEvent) => { // If focus is still within the input container, don't actually blur. if (event.currentTarget.contains(event.relatedTarget)) return; controlState.close(); }, [controlState], ); return (
{children} {controlState.isOpen && ( )}
); }