Select
Displays a list of options for the user to pick from, triggered by a button. Built with React Aria Components' Select and styled with Tailwind CSS and the Tailgrids theme tokens. Labels, descriptions and error messages come from the shared Field parts (FieldLabel, FieldDescription, FieldError).
Installation
Install the component using the Tailgrids CLI.
npx @tailgrids/cli@latest add selectAnatomy
Import the component and pass the required props.
import {
Select,
SelectContent,
SelectValue,
SelectItem,
SelectTrigger
} from "@/components/tailgrids/select";
export default function SelectExample() {
return (
<Select aria-label="Fruit" placeholder="Select a fruit">
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem id="apple">Apple</SelectItem>
<SelectItem id="banana">Banana</SelectItem>
<SelectItem id="orange">Orange</SelectItem>
</SelectContent>
</Select>
);
}Examples
With label and description
Add a label and description with FieldLabel and FieldDescription from the field component.
Sections
Group options with SelectGroup and SelectLabel. Use SelectSeparator to visually separate groups.
Controlled
You can control the value of the select component using the value and onChange props.
Multiple select
The Select component supports multiple selection using the selectionMode="multiple" prop. You can control the selection using value (an Iterable<Key> or Set<Key>) and onChange.
Custom icon
The trigger renders its own chevron. Put any extra element, such as a leading icon, inside SelectTrigger.
Required
The isRequired prop marks the select as required. Use FieldError to display validation errors.
Custom values
You can pass custom content to SelectItem to create more complex menu items.
Controlled multiple
A controlled version of the multiple select example.
Selected count: 1
Disabled
You can disable the entire select component or individual items using the isDisabled prop.
API Reference
Select
| Prop | Type | Default | Description |
|---|---|---|---|
selectionMode | 'single' | 'multiple' | 'single' | Whether single or multiple selection is enabled. |
value | Key | Iterable<Key> | - | The currently selected key(s) (controlled). |
onChange | (value: any) => void | - | Handler that is called when the value changes. |
items | Iterable<T> | - | The items to display in the select. |
name | string | - | The name of the input element, used when submitting an HTML form. |
isDisabled | boolean | - | Whether the select is disabled. |
isInvalid | boolean | - | Whether the select is in an invalid state. |
isRequired | boolean | - | Whether the select requires a value to be selected. |
className | string | - | Additional CSS classes to apply to the select container. |
The Key type supports string and number. See React Aria's Select for more details.
State Attributes
The Select component supports the following state attributes on its container:
| Attribute | Description |
|---|---|
data-focused | Whether the select is currently focused. |
data-open | Whether the select is currently open. |
data-invalid | Whether the select is in an invalid state. |
data-disabled | Whether the select is disabled. |
data-required | Whether the select is required. |
SelectTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'default' | 'default' | The size of the trigger. |
className | string | - | Additional CSS classes to apply to the trigger button. |
SelectContent
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes to apply to the popover content. |
SelectPopover
The underlying popover container used by SelectContent. Extends React Aria Popover props.
| Prop | Type | Default | Description |
|---|---|---|---|
placement | Placement | - | The placement of the popover relative to the trigger. |
offset | number | - | Distance between the trigger and the popover. |
crossOffset | number | - | Distance along the trigger's edge. |
isNonModal | boolean | false | Whether the popover allows interaction outside without closing. |
children | React.ReactNode | - | Content rendered inside the popover. |
className | string | - | Additional CSS classes to apply to the popover. |
SelectItem
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | number | - | The unique identifier for the item. |
textValue | string | - | A text representation of the item's content, used for keyboard navigation and accessibility. |
isDisabled | boolean | - | Whether the item is disabled. |
className | string | - | Additional CSS classes to apply to the item. |
SelectValue
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes to apply to the selected value output. |
SelectGroup, SelectLabel, SelectSeparator, SelectList, SelectInput, SelectEmpty
Each accepts className. SelectGroup groups items, SelectLabel is the group heading, SelectList renders the list box, SelectInput adds a search field and SelectEmpty shows content when nothing matches.
See React Aria's Select for more details.
Accessibility
- Keyboard Navigation: Supports arrow keys to navigate options, Enter/Space to select, and Escape to close the menu.
- Screen Reader Support: Uses ARIA attributes (e.g.,
aria-expanded,aria-activedescendant) to provide context to screen readers. - Labeling: Supports labeling via
FieldLabel,aria-labeloraria-labelledby.
