Select
A custom dropdown for selecting a single value from a list of options.
Installation
pnpm dlx stera-ui add selectUsage
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectSeparator,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"<Select>
<SelectTrigger className="w-48">
<SelectValue placeholder="Select a fruit" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem value="apple">Apple</SelectItem>
<SelectItem value="banana">Banana</SelectItem>
</SelectGroup>
</SelectContent>
</Select>With Groups
Use SelectGroup, SelectLabel, and SelectSeparator to organize options into labelled sections.
<SelectContent>
<SelectGroup>
<SelectLabel>Fruits</SelectLabel>
<SelectItem value="Apple">Apple</SelectItem>
<SelectItem value="Banana">Banana</SelectItem>
</SelectGroup>
<SelectSeparator />
<SelectGroup>
<SelectLabel>Vegetables</SelectLabel>
<SelectItem value="Carrot">Carrot</SelectItem>
<SelectItem value="Broccoli">Broccoli</SelectItem>
</SelectGroup>
</SelectContent>Sizes
sm
md
lg
xl
| Size | Description |
|---|---|
sm | Small |
md | Medium (default) |
lg | Large |
xl | Extra large |
Disabled
<Select disabled>
<SelectTrigger className="w-48">
<SelectValue placeholder="Select a fruit" />
</SelectTrigger>
...
</Select>Invalid
Please select a fruit.
<Field data-invalid>
<FieldLabel>Fruit</FieldLabel>
<Select>
<SelectTrigger aria-invalid>
<SelectValue placeholder="Select a fruit" />
</SelectTrigger>
...
</Select>
<FieldError>Please select a fruit.</FieldError>
</Field>API Reference
Select
Select is an alias for Base UI's Select.Root. Accepts all its props.
| Prop | Type | Default |
|---|---|---|
value | string | — |
defaultValue | string | — |
onValueChange | (value: string) => void | — |
disabled | boolean | false |
name | string | — |
SelectTrigger
| Prop | Type | Default |
|---|---|---|
size | "sm" | "md" | "lg" | "xl" | "md" |
SelectContent
| Prop | Type | Default |
|---|---|---|
side | "top" | "bottom" | "left" | "right" | "bottom" |
align | "start" | "center" | "end" | "center" |
sideOffset | number | 4 |
alignItemWithTrigger | boolean | true |
SelectItem
| Prop | Type | Default |
|---|---|---|
value | string | — |
disabled | boolean | false |