Components
A Select displays a collapsible list of options and allows a user to select one of them.
A select can be built using the <select> and <option> HTML elements, but this is not possible to style consistently cross browser, especially the options. Select helps achieve accessible select components that can be styled as needed without compromising on high quality interactions.
npx shadcn@latest add https://21st.dev/r/jolbol1/selectStarting preview...
import { Label } from "@/components/ui/field"
import {
Select,
SelectItem,
SelectListBox,
SelectPopover,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
export function SelectDemo() {
return (
<Select className="w-[200px]" placeholder="Select an animal">
<Label>Favorite Animal</Label>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectPopover>
<SelectListBox>
<SelectItem>Aardvark</SelectItem>
<SelectItem>Cat</SelectItem>
<SelectItem>Dog</SelectItem>
<SelectItem>Kangaroo</SelectItem>
<SelectItem>Panda</SelectItem>
<SelectItem>Snake</SelectItem>
</SelectListBox>
</SelectPopover>
</Select>
)
}