Introducing PrimeReact v11-alpha 🎉Discover Now

Listbox

An unstyled listbox component with keyboard navigation, type-ahead search, and single or multiple selection.

Build fully custom option lists with complete control over layout and styling.

  • New York
  • Rome
  • London
  • Istanbul
  • Paris
basic-demo

Pre-styled Versions

Choose a pre-styled library to use Listbox with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with sub-components: Root, List, Option, OptionIndicator, Header, Filter, Empty, Footer
  • Single and multiple selection with keyboard focus cycling and type-ahead search
  • Option grouping with group header rendering
  • Built-in filter input integration with customizable filtering logic

Usage#

import { Listbox } from 'primereact/listbox';
<Listbox.Root>
    <Listbox.Header>
        <Listbox.Filter />
    </Listbox.Header>
    <Listbox.List>
        <Listbox.Option>
            <Listbox.OptionIndicator />
        </Listbox.Option>
    </Listbox.List>
    <Listbox.Empty />
    <Listbox.Footer />
</Listbox.Root>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<Listbox.Root as="section">
    <Listbox.List as="div">...</Listbox.List>
</Listbox.Root>

Render Function Children#

Listbox.List accepts a render function as children, providing access to the component instance for custom option rendering.

<Listbox.List>
    {(instance) =>
        instance.options?.map((option, index) => (
            <Listbox.Option key={index} index={index}>
                {instance.listbox?.getOptionLabel(option)}
            </Listbox.Option>
        ))
    }
</Listbox.List>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

ListboxRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ListboxRootInstance) => string)—
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>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceListboxRootInstance<T>—
The instance to pass to the component.
ptSafeRecord<ListboxRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ListboxRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
valueunknown—
The current value of the listbox. For single selection, this is a single value. For multiple selection, this is an array of values.
defaultValueunknown—
The default value of the listbox when used in uncontrolled mode.
optionsT[]—
An array of options to display in the listbox.
optionKeystring—
Unique key for each option.
optionLabelstring—
Label field for each option.
optionValuestring—
Value field for each option.
optionDisabledstring—
Field to check if an option is disabled.
optionGroupLabelstring—
Label field for option groups.
optionGroupChildrenstring—
Field that contains the children options in a group.
disabledboolean—
When present, it specifies that the listbox should be disabled.
invalidboolean—
When present, it specifies that the component should have invalid state style.
localestring—
The locale to use for localization. Used for accessibility labels.
multipleboolean—
When present, allows selecting multiple options.
metaKeySelectionboolean—
When enabled, requires holding the meta key (Ctrl/Cmd) to select/deselect items in multiple selection mode.
autoOptionFocusboolean—
When enabled, the focused option is automatically highlighted.
selectOnFocusboolean—
When enabled, the focused option is automatically selected.
focusOnHoverboolean—
When enabled, the focused option changes on hover.
onValueChange(event: useListboxValueChangeEvent) => void—
Callback to invoke when the value changes.
tabIndexnumber—
Index of the element in tabbing order.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of Listbox component.

labeltypedescription
rootListboxRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
hiddenElementListboxRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the hidden sentinel element's DOM element.
headerListboxRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the header's DOM element.
footerListboxRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the footer's DOM element.
listListboxRootPassThroughType<HTMLAttributes<HTMLUListElement>>Used to pass attributes to the list's DOM element.
emptyListboxRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the empty message's DOM element.
optionGroupListboxRootPassThroughType<HTMLAttributes<HTMLLIElement>>Used to pass attributes to the option group's DOM element.
optionListboxRootPassThroughType<HTMLAttributes<HTMLLIElement>>Used to pass attributes to the option's DOM element.
optionIndicatorListboxRootPassThroughType<HTMLAttributes<HTMLElement>>Used to pass attributes to the option indicator's DOM element.
filterListboxRootPassThroughType<HTMLAttributes<HTMLElement>>Used to pass attributes to the filter's DOM element.

ListboxList#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxListInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ListboxListInstance) => string)—
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>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceListboxListInstance<T>—
The instance to pass to the component.
ptSafeRecord<ListboxListPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ListboxListInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ListboxList component.

labeltypedescription
rootListboxListPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

ListboxOption#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxOptionInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ListboxOptionInstance) => string)—
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>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceListboxOptionInstance<T>—
The instance to pass to the component.
ptSafeRecord<ListboxOptionPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ListboxOptionInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
groupboolean—
When enabled, renders the option as a group header.
uKeyPropertyKey—
Unique key for the option. Used for identification and selection.
indexnumber—
Index of the option in the list.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-selectedPresent when selected
data-unselectedPresent when unselected
data-focusedPresent when focused
data-disabledPresent when disabled

Defines passthrough(pt) options of ListboxOption component.

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

ListboxOptionIndicator#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxOptionIndicatorInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ListboxOptionIndicatorInstance) => string)—
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>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceListboxOptionIndicatorInstance<T>—
The instance to pass to the component.
ptSafeRecord<ListboxOptionIndicatorPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ListboxOptionIndicatorInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
match"always" | "selected" | "unselected"—
Determines the visibility of the indicator based on the selection state of the option. - "always": Indicator is always visible. - "selected": Indicator is visible only when the option is selected. - "unselected": Indicator is visible only when the option is not selected.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-selectedPresent when selected
data-unselectedPresent when unselected

Defines passthrough(pt) options of ListboxOptionIndicator component.

labeltypedescription
rootListboxOptionIndicatorPassThroughType<HTMLAttributes<HTMLElement>>Used to pass attributes to the root's DOM element.

ListboxHeader#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxHeaderInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ListboxHeaderInstance) => string)—
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>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceListboxHeaderInstance—
The instance to pass to the component.
ptSafeRecord<ListboxHeaderPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ListboxHeaderInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ListboxHeader component.

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

ListboxFilter#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxFilterInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ListboxFilterInstance) => string)—
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>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceListboxFilterInstance—
The instance to pass to the component.
ptSafeRecord<ListboxFilterPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ListboxFilterInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ListboxFilter component.

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

ListboxEmpty#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxEmptyInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ListboxEmptyInstance) => string)—
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>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceListboxEmptyInstance—
The instance to pass to the component.
ptSafeRecord<ListboxEmptyPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ListboxEmptyInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ListboxEmpty component.

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

ListboxFooter#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ListboxFooterInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ListboxFooterInstance) => string)—
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>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceListboxFooterInstance—
The instance to pass to the component.
ptSafeRecord<ListboxFooterPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ListboxFooterInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ListboxFooter component.

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

Accessibility#

Screen Reader#

A value to describe the component can be provided with aria-labelledby or aria-label props. The list element has a listbox role with aria-multiselectable set to true when multiple selection is enabled. Each list item has an option role with aria-selected and aria-disabled attributes.

When metaKeySelection is enabled, pointer-based multi-selection requires a platform meta key (Ctrl on Windows/Linux and Cmd on macOS). Keyboard interaction remains available through standard listbox shortcuts.

Keyboard Support#

KeyFunction
tabMoves focus to the first selected option, if there is none then first option receives the focus.
up arrowMoves focus to the previous option.
down arrowMoves focus to the next option.
enterToggles the selected state of the focused option.
spaceToggles the selected state of the focused option.
homeMoves focus to the first option.
endMoves focus to the last option.
shift + down arrowMoves focus to the next option and toggles the selection state.
shift + up arrowMoves focus to the previous option and toggles the selection state.
shift + spaceSelects the items between the most recently selected option and the focused option.
control + shift + homeSelects the focused option and all the options up to the first one.
control + shift + endSelects the focused option and all the options down to the last one.
control + aSelects all options.
page upJumps visual focus to the first option.
page downJumps visual focus to the last option.
any printable characterMoves focus to the option whose label starts with the characters being typed.

Filter Input Keyboard Support#

KeyFunction
down arrowMoves focus to the next option, if there is none then visual focus does not change.
up arrowMoves focus to the previous option, if there is none then visual focus does not change.
left arrowRemoves the visual focus from the current option and moves input cursor to one character left.
right arrowRemoves the visual focus from the current option and moves input cursor to one character right.
homeMoves input cursor at the beginning, if not then moves focus to the first option.
endMoves input cursor at the end, if not then moves focus to the last option.
tabMoves focus to the next focusable element in the component. If there is none, moves focus to next element in page.