1 ---
2 generate_toc: true
3 ---
4
5 import { ComponentExample } from "@/components/ComponentExample"
6 import { ComponentReference } from "@/components/ComponentReference"
7
8 export const metadata = {
9 title: `Select`,
10 }
11
12 # {metadata.title}
13
14 A component that displays a select form input using Medusa's design system.
15
16 In this guide, you'll learn how to use the Select component.
17
18 <ComponentExample name="select-demo" />
19
20 ## Usage
21
22 ```tsx
23 import { Select } from "@medusajs/ui"
24 ```
25
26 ```tsx
27 <Select>
28 <Select.Trigger>
29 <Select.Value placeholder="Placeholder" />
30 </Select.Trigger>
31 <Select.Content>
32 {items.map((item) => (
33 <Select.Item key={item.value} value={item.value}>
34 {item.label}
35 </Select.Item>
36 ))}
37 </Select.Content>
38 </Select>
39 ```
40
41 ---
42
43 ## API Reference
44
45 <ComponentReference mainComponent="Select" componentsToShow={[
46 "Select",
47 "Select.Trigger",
48 "Select.Value",
49 "Select.Group",
50 "Select.Label",
51 "Select.Item",
52 "Select.Content"
53 ]} />
54
55 ---
56
57 ## Examples
58
59 ### Small Select
60
61 <ComponentExample name="select-small" />
62
63 ### Select Item-Aligned Position
64
65 <ComponentExample name="select-item-aligned" />
66
67 ### Disabled Select
68
69 <ComponentExample name="select-disabled" />
70
71 ### Select with Grouped Items
72
73 <ComponentExample name="select-grouped-items" />
74
75 ### Controlled Select
76
77 <ComponentExample name="select-controlled" hideFeedback />
78
79 ### Empty Values
80
81 A `Select.Item` can't have an empty string as its `value` prop. If you do, you'll get the error `A <Select.Item /> must have a value prop that is not an empty string`. This is because the Select reserves the empty string to clear the selection and show the placeholder.
82
83 To add an option like `None`, use a non-empty placeholder value, then convert it in your change handler:
84
85 ```tsx
86 <Select
87 onValueChange={(value) =>
88 handleChange(value === "none" ? null : value)
89 }
90 >
91 <Select.Trigger>
92 <Select.Value placeholder="Placeholder" />
93 </Select.Trigger>
94 <Select.Content>
95 <Select.Item value="none">None</Select.Item>
96 {items.map((item) => (
97 <Select.Item key={item.value} value={item.value}>
98 {item.label}
99 </Select.Item>
100 ))}
101 </Select.Content>
102 </Select>
103 ```