default.tsx
1'use client';23import { Select } from '@/components/ui/select';45const options = [6 { value: '1', label: 'Option 1' },7 { value: '2', label: 'Option 2' },8 { value: '3', label: 'Option 3' },9];1011export function Default() {12 return (13 <div className="w-full max-w-xs">14 <Select defaultValue="" aria-label="Select an option">15 <option value="" disabled>16 Select an option17 </option>18 {options.map((option) => (19 <option key={option.value} value={option.value}>20 {option.label}21 </option>22 ))}23 </Select>24 </div>25 );26}
Installation
pnpm dlx nachui add selectAnatomy
1import { Select } from '@/components/ui/select';
1<Select>2 <option value="1">Option 1</option>3</Select>
Variants
Default
default.tsx
1'use client';23import { Select } from '@/components/ui/select';45const options = [6 { value: '1', label: 'Option 1' },7 { value: '2', label: 'Option 2' },8 { value: '3', label: 'Option 3' },9];1011export function Default() {12 return (13 <div className="w-full max-w-xs">14 <Select defaultValue="" aria-label="Select an option">15 <option value="" disabled>16 Select an option17 </option>18 {options.map((option) => (19 <option key={option.value} value={option.value}>20 {option.label}21 </option>22 ))}23 </Select>24 </div>25 );26}
Grouped Items
Use
optgroup to group related options together.grouped-items.tsx
1'use client';23import { Select } from '@/components/ui/select';45const groups = [6 {7 label: 'Citrus',8 options: [9 { value: 'orange', label: 'Orange' },10 { value: 'lemon', label: 'Lemon' },11 { value: 'lime', label: 'Lime' },12 ],13 },14 {15 label: 'Berries',16 options: [17 { value: 'strawberry', label: 'Strawberry' },18 { value: 'blueberry', label: 'Blueberry' },19 { value: 'raspberry', label: 'Raspberry' },20 ],21 },22] as const;2324export function GroupedItems() {25 return (26 <div className="w-full max-w-xs">27 <Select defaultValue="" aria-label="Select a fruit">28 <option value="" disabled>29 Select a fruit30 </option>31 {groups.map((group) => (32 <optgroup key={group.label} label={group.label}>33 {group.options.map((opt) => (34 <option key={opt.value} value={opt.value}>35 {opt.label}36 </option>37 ))}38 </optgroup>39 ))}40 </Select>41 </div>42 );43}
API Reference
Select
| Prop | Type | Default | Description |
|---|---|---|---|
wrapperClassName | string | - | Additional CSS classes for the container div |
className | string | - | Additional CSS classes for the select element |
disabled | boolean | - | Disables the select menu |
Found something to improve?
Notice a bug, typo, or missing detail on this page? Help us make the documentation better by opening a GitHub issue.