UNPKG

@acusti/dropdown

Version:

React component that renders a dropdown with a trigger and supports searching, keyboard access, and more

70 lines (69 loc) 2.57 kB
import { CSSProperties, MouseEvent as ReactMouseEvent, ReactElement, ReactNode, SyntheticEvent } from 'react'; export type Item = { element: MaybeHTMLElement; event: Event | SyntheticEvent<HTMLElement>; label: string; value: string; }; export type Props = { /** * Boolean indicating if the user can submit a value not already in the * dropdown. */ allowCreate?: boolean; /** * Boolean indicating if the user can submit an empty value (i.e. clear * the value). Defaults to true. */ allowEmpty?: boolean; /** * Can take a single React element or exactly two renderable children. */ children: ChildrenTuple | ReactElement; className?: string; disabled?: boolean; /** * Group identifier string links dropdowns together into a menu * (like macOS top menubar). */ group?: string; hasItems?: boolean; isOpenOnMount?: boolean; isSearchable?: boolean; keepOpenOnSubmit?: boolean; label?: ReactNode; minHeightBody?: number; minWidthBody?: number; /** * Only usable in conjunction with {isSearchable: true}. * Used as search input’s name. */ name?: string; onActiveItem?: (payload: Item) => void; onClick?: (event: ReactMouseEvent<HTMLElement>) => unknown; onClose?: () => unknown; onMouseDown?: (event: ReactMouseEvent<HTMLElement>) => unknown; onMouseUp?: (event: ReactMouseEvent<HTMLElement>) => unknown; onOpen?: () => unknown; onSubmitItem?: (payload: Item) => void; /** * Only usable in conjunction with {isSearchable: true}. * Used as search input’s placeholder. */ placeholder?: string; style?: CSSProperties; /** * Only usable in conjunction with {isSearchable: true}. * Used as search input’s tabIndex. */ tabIndex?: number; /** * Used as search input’s value if props.isSearchable === true * Used to determine if value has changed to avoid triggering onSubmitItem if not */ value?: string; }; type ChildrenTuple = [ReactNode, ReactNode] | readonly [ReactNode, ReactNode]; type MaybeHTMLElement = HTMLElement | null; export default function Dropdown({ allowCreate, allowEmpty, children, className, disabled, hasItems, isOpenOnMount, isSearchable, keepOpenOnSubmit, label, minHeightBody, minWidthBody, name, onActiveItem, onClick, onClose, onMouseDown, onMouseUp, onOpen, onSubmitItem, placeholder, style: styleFromProps, tabIndex, value, }: Props): import("react/jsx-runtime").JSX.Element; export {};