form
A dropdown for picking one option from a list. Put it inside a Field for the label and errors.
npx blankui add selectBuilt on Radix. Use value and onValueChange (or defaultValue). Item values must be non-empty strings.
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
<Field label="Role">
<Select value={role} onValueChange={setRole}>
<SelectTrigger>
<SelectValue placeholder="Pick a role" />
</SelectTrigger>
<SelectContent>
<SelectItem value="admin">Admin</SelectItem>
<SelectItem value="member">Member</SelectItem>
<SelectItem value="viewer">Viewer</SelectItem>
</SelectContent>
</Select>
</Field>
<SelectContent>
<SelectGroup>
<SelectLabel>Fruits</SelectLabel>
<SelectItem value="apple">Apple</SelectItem>
</SelectGroup>
<SelectSeparator />
<SelectGroup>
<SelectLabel>Vegetables</SelectLabel>
<SelectItem value="carrot">Carrot</SelectItem>
</SelectGroup>
</SelectContent>
Pass name to Select to include the value in a native form submit.
| Avoid | Instead |
|---|---|
| <select><option>...</option></select> (a raw select element) | <Select> with SelectTrigger, SelectValue, SelectContent and SelectItem |
| onChange={(e) => setValue(e.target.value)} | onValueChange={setValue} |
| <SelectItem value="">None</SelectItem> | Leave the Select empty and use the SelectValue placeholder |
Install with the shadcn CLI: npx shadcn add https://blank.vageshwar.dev/r/select.json