import { CollectionItem, ListCollection } from '@zag-js/collection'; export { CollectionItem, CollectionOptions } from '@zag-js/collection'; import { Machine, EventObject, Service } from '@zag-js/core'; import { InteractOutsideHandlers } from '@zag-js/dismissable'; import { TypeaheadState } from '@zag-js/dom-query'; import { PositioningOptions, Placement } from '@zag-js/popper'; export { PositioningOptions } from '@zag-js/popper'; import { PropTypes, RequiredBy, DirectionProperty, CommonProperties } from '@zag-js/types'; interface ValueChangeDetails { value: string[]; items: T[]; } interface HighlightChangeDetails { highlightedValue: string | null; highlightedItem: T | null; highlightedIndex: number; } interface OpenChangeDetails { open: boolean; value: string[]; } interface ScrollToIndexDetails { index: number; immediate?: boolean | undefined; getElement: () => HTMLElement | null; } interface SelectionDetails { value: string; } interface IntlTranslations { clearTriggerLabel?: string | undefined; } type ElementIds = Partial<{ root: string; content: string; control: string; trigger: string; clearTrigger: string; label: string; hiddenSelect: string; positioner: string; item: (id: string | number) => string; itemGroup: (id: string | number) => string; itemGroupLabel: (id: string | number) => string; }>; interface SelectProps extends DirectionProperty, CommonProperties, InteractOutsideHandlers { /** * Specifies the localized strings that identifies the accessibility elements and their states */ translations?: IntlTranslations | undefined; /** * The item collection */ collection: ListCollection; /** * The ids of the elements in the select. Useful for composition. */ ids?: ElementIds | undefined; /** * The `name` attribute of the underlying select. */ name?: string | undefined; /** * The associate form of the underlying select. */ form?: string | undefined; /** * The autocomplete attribute for the hidden select. Enables browser autofill (e.g. "address-level1" for state). */ autoComplete?: string | undefined; /** * Whether the select is disabled */ disabled?: boolean | undefined; /** * Whether the select is invalid */ invalid?: boolean | undefined; /** * Whether the select is read-only */ readOnly?: boolean | undefined; /** * Whether the select is required */ required?: boolean | undefined; /** * Whether the select should close after an item is selected * @default true */ closeOnSelect?: boolean | undefined; /** * Function called when an item is selected */ onSelect?: ((details: SelectionDetails) => void) | undefined; /** * The callback fired when the highlighted item changes. */ onHighlightChange?: ((details: HighlightChangeDetails) => void) | undefined; /** * The callback fired when the selected item changes. */ onValueChange?: ((details: ValueChangeDetails) => void) | undefined; /** * Function called when the popup is opened */ onOpenChange?: ((details: OpenChangeDetails) => void) | undefined; /** * The positioning options of the menu. */ positioning?: PositioningOptions | undefined; /** * The controlled keys of the selected items */ value?: string[] | undefined; /** * The initial default value of the select when rendered. * Use when you don't need to control the value of the select. */ defaultValue?: string[] | undefined; /** * The controlled key of the highlighted item */ highlightedValue?: string | null | undefined; /** * The initial value of the highlighted item when opened. * Use when you don't need to control the highlighted value of the select. */ defaultHighlightedValue?: string | null | undefined; /** * Whether to loop the keyboard navigation through the options * @default false */ loopFocus?: boolean | undefined; /** * Whether to allow multiple selection */ multiple?: boolean | undefined; /** * Whether the select menu is open */ open?: boolean | undefined; /** * Whether the select's open state is controlled by the user */ defaultOpen?: boolean | undefined; /** * Function to scroll to a specific index */ scrollToIndexFn?: ((details: ScrollToIndexDetails) => void) | undefined; /** * Whether the select is a composed with other composite widgets like tabs or combobox * @default true */ composite?: boolean | undefined; /** * Whether the value can be cleared by clicking the selected item. * * **Note:** this is only applicable for single selection */ deselectable?: boolean | undefined; } type PropsWithDefault = "positioning" | "closeOnSelect" | "loopFocus" | "composite" | "collection" | "translations"; interface SelectSchema { state: "idle" | "focused" | "open"; props: RequiredBy, PropsWithDefault>; context: { currentPlacement: Placement | undefined; value: string[]; highlightedValue: string | null; fieldsetDisabled: boolean; highlightedItem: T | null; selectedItemMap: Map; }; computed: { hasSelectedItems: boolean; isTypingAhead: boolean; isInteractive: boolean; isDisabled: boolean; selectedItems: T[]; valueAsString: string; }; refs: { typeahead: TypeaheadState; }; action: string; guard: string; effect: string; event: EventObject; } type SelectService = Service>; type SelectMachine = Machine>; interface ItemProps { /** * The item to render */ item: T; /** * Whether hovering outside should clear the highlighted state */ persistFocus?: boolean | undefined; } interface ItemState { /** * The underlying value of the item */ value: string; /** * Whether the item is disabled */ disabled: boolean; /** * Whether the item is selected */ selected: boolean; /** * Whether the item is highlighted */ highlighted: boolean; } interface ItemGroupProps { id: string; } interface ItemGroupLabelProps { htmlFor: string; } interface SelectApi { /** * Whether the select is focused */ focused: boolean; /** * Whether the select is open */ open: boolean; /** * Whether the select value is empty */ empty: boolean; /** * The value of the highlighted item */ highlightedValue: string | null; /** * The highlighted item */ highlightedItem: V | null; /** * Function to highlight a value */ setHighlightValue: (value: string) => void; /** * Function to clear the highlighted value */ clearHighlightValue: VoidFunction; /** * The selected items */ selectedItems: V[]; /** * Whether there's a selected option */ hasSelectedItems: boolean; /** * The selected item keys */ value: string[]; /** * The string representation of the selected items */ valueAsString: string; /** * Function to select a value */ selectValue: (value: string) => void; /** * Function to select all values */ selectAll: VoidFunction; /** * Function to set the value of the select */ setValue: (value: string[]) => void; /** * Function to clear the value of the select. * If a value is provided, it will only clear that value, otherwise, it will clear all values. */ clearValue: (value?: string) => void; /** * Function to focus on the select input */ focus: VoidFunction; /** * Returns the state of a select item */ getItemState: (props: ItemProps) => ItemState; /** * Function to open or close the select */ setOpen: (open: boolean) => void; /** * Function to toggle the select */ collection: ListCollection; /** * Function to set the positioning options of the select */ reposition: (options?: Partial) => void; /** * Whether the select allows multiple selections */ multiple: boolean; /** * Whether the select is disabled */ disabled: boolean; getRootProps: () => T["element"]; getLabelProps: () => T["label"]; getControlProps: () => T["element"]; getTriggerProps: () => T["button"]; getIndicatorProps: () => T["element"]; getClearTriggerProps: () => T["button"]; getValueTextProps: () => T["element"]; getPositionerProps: () => T["element"]; getContentProps: () => T["element"]; getListProps: () => T["element"]; getItemProps: (props: ItemProps) => T["element"]; getItemTextProps: (props: ItemProps) => T["element"]; getItemIndicatorProps: (props: ItemProps) => T["element"]; getItemGroupProps: (props: ItemGroupProps) => T["element"]; getItemGroupLabelProps: (props: ItemGroupLabelProps) => T["element"]; getHiddenSelectProps: () => T["select"]; } export type { ElementIds, HighlightChangeDetails, IntlTranslations, ItemGroupLabelProps, ItemGroupProps, ItemProps, ItemState, OpenChangeDetails, ScrollToIndexDetails, SelectApi, SelectMachine, SelectProps, SelectSchema, SelectService, SelectionDetails, ValueChangeDetails };