Listbox API

API documentation for Listbox component

Listbox#

Props#

Defines valid properties in Listbox component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: ListboxInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<ListboxPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: ListboxInstance) => ReactNode)
null
The children to render.
checkmarkboolean
null
When enabled, displays a checkmark icon next to the selected option.
checkboxboolean
null
When enabled, displays checkboxes for multiple selection mode.
invalidboolean
null
When present, it specifies that the component should have invalid state style.
tabIndexnumber
null
Index of the element in tabbing order.
valueunknown
null
The current value of the listbox. For single selection, this is a single value. For multiple selection, this is an array of values.
defaultValueunknown
null
The default value of the listbox when used in uncontrolled mode.
optionsunknown[]
null
An array of options to display in the listbox.
optionKeystring
null
Unique key for each option.
optionLabelstring
null
Label field for each option.
optionValuestring
null
Value field for each option.
optionDisabledstring
null
Field to check if an option is disabled.
optionGroupLabelstring
null
Label field for option groups.
optionGroupChildrenstring
null
Field that contains the children options in a group.
disabledboolean
null
When present, it specifies that the listbox should be disabled.
localestring
null
The locale to use for localization. Used for accessibility labels.
multipleboolean
null
When present, allows selecting multiple options.
metaKeySelectionboolean
null
When enabled, requires holding the meta key (Ctrl/Cmd) to select/deselect items in multiple selection mode.
autoOptionFocusboolean
null
When enabled, the focused option is automatically highlighted.
selectOnFocusboolean
null
When enabled, the focused option is automatically selected.
focusOnHoverboolean
null
When enabled, the focused option changes on hover.
onValueChange(event: useListboxValueChangeEvent) => void
null
Callback to invoke when the value changes.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

State#

Defines valid state in Listbox component.

nametypedefaultdescription
valueunknown
null
The current value(s) selected in the listbox.
focusedboolean
null
Whether the listbox is currently focused.
focusedOptionIndexnumber
null
The index of the currently focused option. -1 if no option is focused.

Exposes#

Defines the methods and properties exposed by Listbox component.

nametypedefaultdescription
stateuseListboxState
null
The state of the useListbox.
listRefRefObject<HTMLElement>
null
Reference to the list element of the listbox.
firstHiddenFocusableRefRefObject<HTMLElement>
null
Reference to the first hidden focusable element for accessibility.
lastHiddenFocusableRefRefObject<HTMLElement>
null
Reference to the last hidden focusable element for accessibility.
getOptions() => unknown[]
null
Gets the list of options for the listbox.
getOptionId(index: number) => string
null
Gets the unique ID for an option at a given index.
getOptionLabel(option: unknown) => string
null
Gets the label for a given option.
getOptionValue(option: unknown) => unknown
null
Gets the value for a given option.
isOptionDisabled(option: unknown) => boolean
null
Checks if a given option is disabled.
isOptionGroup(option: unknown) => boolean
null
Checks if a given option is a group header.
getOptionGroupLabel(optionGroup: unknown) => string
null
Gets the label for a given option group.
getOptionGroupChildren(optionGroup: unknown) => unknown[]
null
Gets the children options for a given option group.
getFocusedOptionId() => string
null
Gets the ID of the currently focused option.
getAriaSetSize() => number
null
Gets the total number of selectable options for ARIA.
getAriaPosInset(index: number) => number
null
Gets the position of an option in the set for ARIA.
onFirstHiddenFocus(event: FocusEvent) => void
null
Callback when the first hidden focusable element receives focus.
onLastHiddenFocus(event: FocusEvent) => void
null
Callback when the last hidden focusable element receives focus.
onFocusOut(event: FocusEvent) => void
null
Callback when focus leaves the listbox.
onListFocus() => void
null
Callback when the list receives focus.
onListBlur() => void
null
Callback when the list loses focus.
onListKeyDown(event: KeyboardEvent) => void
null
Callback for keyboard events on the list.
onOptionSelect(event: MouseEvent<Element, MouseEvent> | KeyboardEvent<Element>, option: unknown, index?: number) => void
null
Callback when an option is selected.
onOptionMouseDown(event: MouseEvent, index: number) => void
null
Callback when mouse button is pressed on an option.
onOptionMouseMove(event: MouseEvent, index: number) => void
null
Callback when mouse moves over an option.
onOptionTouchEnd(event: TouchEvent, index: number) => void
null
Callback when touch ends on an option.
onFilterChange(event: ChangeEvent) => void
null
Callback when the filter value changes.
onFilterBlur(event: FocusEvent) => void
null
Callback when the filter input loses focus.
onFilterKeyDown(event: KeyboardEvent) => void
null
Callback for keyboard events on the filter input.
isOptionMatched(option: unknown, searchValue: string) => boolean
null
Checks if an option matches the search value.
isValidOption(option: unknown) => boolean
null
Checks if an option is valid (not disabled and not a group).
isValidSelectedOption(option: unknown) => boolean
null
Checks if an option is valid for selection.
isSelected(option: unknown) => boolean
null
Checks if an option is currently selected.
changeFocusedOptionIndex(event: MouseEvent<Element, MouseEvent> | KeyboardEvent<Element>, index: number) => void
null
Changes the focused option index.
scrollInView(index: number) => void
null
Scrolls the option at the given index into view.
updateModel(event: MouseEvent<Element, MouseEvent> | KeyboardEvent<Element>, value: unknown) => void
null
Updates the listbox model with a new value.
autoUpdateModel(event: MouseEvent<Element, MouseEvent> | KeyboardEvent<Element>, option: unknown) => void
null
Automatically updates the model based on option selection.
equalityKeystring
null
Property name used for equality comparison.
hasValue() => boolean
null
Checks if the listbox has a value.

Interfaces#

Defines passthrough(pt) options of Listbox component.

nametypedefaultdescription
rootListboxPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the root's DOM element.
firstHiddenFocusableListboxPassThroughType<HTMLAttributes<HTMLSpanElement>>
null
Used to pass attributes to the first hidden focusable element's DOM element.
lastHiddenFocusableListboxPassThroughType<HTMLAttributes<HTMLSpanElement>>
null
Used to pass attributes to the last hidden focusable element's DOM element.
headerListboxPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the header's DOM element.
footerListboxPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the footer's DOM element.
listListboxPassThroughType<HTMLAttributes<HTMLUListElement>>
null
Used to pass attributes to the list's DOM element.
emptyListboxPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the empty message's DOM element.
optionGroupListboxPassThroughType<HTMLAttributes<HTMLLIElement>>
null
Used to pass attributes to the option group's DOM element.
optionListboxPassThroughType<HTMLAttributes<HTMLLIElement>>
null
Used to pass attributes to the option's DOM element.
selectionListboxPassThroughType<HTMLAttributes<HTMLElement>>
null
Used to pass attributes to the selection's DOM element.
filterListboxPassThroughType<HTMLAttributes<HTMLElement>>
null
Used to pass attributes to the filter's DOM element.

Types#

Instance of Listbox component.

values
ComponentInstance<ListboxProps, ListboxState, ListboxExposes>

ListboxHeader#

Props#

Defines valid properties in ListboxHeader component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxHeaderInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: ListboxHeaderInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<ListboxHeaderPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: ListboxHeaderInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Interfaces#

Defines passthrough(pt) options of ListboxHeader component.

nametypedefaultdescription
rootListboxHeaderPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of ListboxHeader component.

values
ComponentInstance<ListboxHeaderProps, ListboxHeaderState, ListboxHeaderExposes>

ListboxFooter#

Props#

Defines valid properties in ListboxFooter component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxFooterInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: ListboxFooterInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<ListboxFooterPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: ListboxFooterInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Interfaces#

Defines passthrough(pt) options of ListboxFooter component.

nametypedefaultdescription
rootListboxFooterPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of ListboxFooter component.

values
ComponentInstance<ListboxFooterProps, ListboxFooterState, ListboxFooterExposes>

ListboxOptions#

Props#

Defines valid properties in ListboxOptions component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxOptionsInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: ListboxOptionsInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<ListboxOptionsPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: ListboxOptionsInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Interfaces#

Defines passthrough(pt) options of ListboxOptions component.

nametypedefaultdescription
rootListboxOptionsPassThroughType<HTMLAttributes<HTMLSpanElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of ListboxOptions component.

values
ComponentInstance<ListboxOptionsProps, ListboxOptionsState, ListboxOptionsExposes>

ListboxOption#

Props#

Defines valid properties in ListboxOption component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxOptionInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: ListboxOptionInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<ListboxOptionPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: ListboxOptionInstance) => ReactNode)
null
The children to render.
groupboolean
null
When enabled, renders the option as a group header.
uKeyPropertyKey
null
Unique key for the option. Used for identification and selection.
indexnumber
null
Index of the option in the list.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Interfaces#

Defines passthrough(pt) options of ListboxOption component.

nametypedefaultdescription
rootListboxOptionPassThroughType<HTMLAttributes<HTMLSpanElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of ListboxOption component.

values
ComponentInstance<ListboxOptionProps, ListboxOptionState, ListboxOptionExposes>

ListboxSelection#

Props#

Defines valid properties in ListboxSelection component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxSelectionInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: ListboxSelectionInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<ListboxSelectionPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: ListboxSelectionInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Interfaces#

Defines passthrough(pt) options of ListboxSelection component.

nametypedefaultdescription
rootListboxSelectionPassThroughType<HTMLAttributes<HTMLElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of ListboxSelection component.

values
ComponentInstance<ListboxSelectionProps, ListboxSelectionState, ListboxSelectionExposes>

ListboxFilter#

Props#

Defines valid properties in ListboxFilter component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxFilterInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: ListboxFilterInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<ListboxFilterPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: ListboxFilterInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Interfaces#

Defines passthrough(pt) options of ListboxFilter component.

nametypedefaultdescription
rootListboxFilterPassThroughType<HTMLAttributes<HTMLSpanElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of ListboxFilter component.

values
ComponentInstance<ListboxFilterProps, ListboxFilterState, ListboxFilterExposes>

ListboxEmpty#

Props#

Defines valid properties in ListboxEmpty component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxEmptyInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: ListboxEmptyInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<ListboxEmptyPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: ListboxEmptyInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Interfaces#

Defines passthrough(pt) options of ListboxEmpty component.

nametypedefaultdescription
rootListboxEmptyPassThroughType<HTMLAttributes<HTMLSpanElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of ListboxEmpty component.

values
ComponentInstance<ListboxEmptyProps, ListboxEmptyState, ListboxEmptyExposes>

useListbox#

Types#

Instance of useListbox headless.

values
HeadlessInstance<useListboxProps, useListboxState, useListboxExposes>