Introducing PrimeReact v11-alpha 🎉Discover Now

Select

Select is used to choose an item from a collection of options.

Installation#

npx shadcn@latest add @primereact/select

Usage#

import { Select, SelectList, SelectOption, SelectPopup, SelectPortal, SelectPositioner, SelectTrigger, SelectValue } from '@/components/ui/select';
<Select options={items} optionLabel="label" optionValue="value">
    <SelectTrigger>
        <SelectValue placeholder="Select an item" />
    </SelectTrigger>
    <SelectPortal>
        <SelectPositioner>
            <SelectPopup>
                <SelectList>
                    {items.map((item, index) => (
                        <SelectOption key={index} index={index}>
                            {item.label}
                        </SelectOption>
                    ))}
                </SelectList>
            </SelectPopup>
        </SelectPositioner>
    </SelectPortal>
</Select>

Examples#

Basic#

Choose a single value from a dropdown list of options.

basic-demo

Sizes#

Use the size property to change the size of a select.

sizes-demo

Filled#

Specify the variant="filled" property to display the component with a higher visual emphasis than the default outlined style.

filled-demo

Disabled#

Use the disabled property to disable a select.

disabled-demo

Invalid#

Specify the invalid property to display the component with a red border for validation errors.

invalid-demo

Multiple#

Use the multiple prop to allow selecting more than one item. Place Select.OptionIndicator inside each option with a check icon to indicate the selection state.

multiple-demo

Chips#

Display selected items as removable chips by composing Chip components inside Select.Value.

chip-demo

Clear#

Use Select.Clear inside the trigger to display a clear button that resets the selection.

clear-icon-demo

Filter#

Add a search field inside the popup using Select.Header with Select.Filter to filter options. The Select.Empty component provides a message when no results match.

filter-demo

Group#

Simple#

Options can be grouped using the optionGroupLabel and optionGroupChildren properties.

group-demo

Custom#

Customize group headers with custom rendering by accessing the list instance inside Select.List.

custom-group-demo

Arrow#

Use Select.Arrow inside the popup to display a visual arrow pointing to the trigger element.

arrow-demo

Fluid#

Use the fluid property to make the select take up the full width of its container.

fluid-demo

Focus Behavior#

Customize keyboard and mouse focus behavior with autoOptionFocus, selectOnFocus, and focusOnHover props.

focus-behavior-demo

API#

Sub-Components#

See Primitive API for SelectRoot, SelectTrigger, SelectList, SelectOption, and other component documentation.

Hooks#

See Headless API for useSelect hook documentation.

Accessibility#

See Select Primitive for WAI-ARIA compliance details and keyboard support.