/
docs.forms.select.jsx
252 lines (239 loc) · 7.8 KB
/
docs.forms.select.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import { useRef } from "react";
import Code from "~/components/Code";
import Heading from "~/components/Heading";
import Link from "~/components/Link";
import Content from "~/components/docs/Content";
import EditOnGithub from "~/components/docs/EditOnGithub";
import Header from "~/components/docs/Header";
import TableOfContents from "~/components/docs/TableOfContents";
import metaData from "~/data/meta";
const { titleSuffix } = metaData;
export const meta = () => [
{ title: `Select ${titleSuffix}` },
{
name: "description",
content: "The native <select> is styled like the input for consistency.",
},
];
export default function Select() {
const syntaxRef = useRef();
const multipleRef = useRef();
const disabledRef = useRef();
const validationStatesRef = useRef();
const dropdownRef = useRef();
return (
<>
{/* Header */}
<Header
title="Select"
description={
<>
The native <Code display="inline">{`<select>`}</Code> is styled like the input for
consistency.
</>
}
/>
{/* Table of content */}
<TableOfContents
data={[
{
anchor: "",
title: "Syntax",
ref: syntaxRef,
},
{
anchor: "multiple",
title: "Multiple",
ref: multipleRef,
},
{
anchor: "disabled",
title: "Disabled",
ref: disabledRef,
},
{
anchor: "validation-states",
title: "Validation states",
ref: validationStatesRef,
},
{
anchor: "dropdown",
title: "Dropdown",
ref: dropdownRef,
},
]}
/>
{/* Content */}
<Content>
<section ref={syntaxRef}>
<article aria-label="Select example" className="component">
<select
name="favorite-cuisine"
aria-label=" Select your favorite cuisine..."
defaultValue=""
required
>
<option disabled value="">
Select your favorite cuisine...
</option>
<option>Italian</option>
<option>Japanese</option>
<option>Indian</option>
<option>Thai</option>
<option>French</option>
</select>
<Code as="footer">{`<select name="favorite-cuisine" aria-label="Select your favorite cuisine..." required>
<option selected disabled value="">
Select your favorite cuisine...
</option>
<option>Italian</option>
<option>Japanese</option>
<option>Indian</option>
<option>Thai</option>
<option>French</option>
</select>`}</Code>
</article>
</section>
<section ref={multipleRef}>
<Heading level={2} anchor="multiple">
Select multiple
</Heading>
<article aria-label="Disabled and read-only example" className="component">
<select
aria-label="Select your favorite snacks..."
defaultValue={["Fruits", "Nuts"]}
multiple
size="6"
>
<option disabled>Select your favorite snacks...</option>
<option>Cheese</option>
<option>Fruits</option>
<option>Nuts</option>
<option>Chocolate</option>
<option>Crackers</option>
</select>
<Code as="footer">{`<select aria-label="Select your favorite snacks..." multiple size="6">
<option disabled>
Select your favorite snacks...
</option>
<option>Cheese</option>
<option selected>Fruits</option>
<option selected>Nuts</option>
<option>Chocolate</option>
<option>Crackers</option>
</select>`}</Code>
</article>
</section>
<section ref={disabledRef}>
<Heading level={2} anchor="disabled">
Disabled select
</Heading>
<article aria-label="Disabled example" className="component">
<select name="meal-type" aria-label="Select a meal type..." disabled>
<option>Select a meal type...</option>
</select>
<Code as="footer">{`<select name="meal-type" aria-label="Select a meal type..." disabled>
<option>Select a meal type...</option>
<option>...</option>
</select>`}</Code>
</article>
</section>
<section ref={validationStatesRef}>
<Heading level={2} anchor="validation-states">
Validation states
</Heading>
<p>
Validation states are provided with <code>aria-invalid</code>.
</p>
<article aria-label="Validation states example" className="component">
<select
name="pizza-topping"
aria-label="Select your favorite pizza topping..."
defaultValue="Pepperoni"
aria-invalid="false"
>
<option disabled>Select your favorite pizza topping...</option>
<option>Pepperoni</option>
<option>Mushrooms</option>
<option>Onions</option>
<option>Green Peppers</option>
<option>Olives</option>
</select>
<small>Great choice!</small>
<select
name="pizza-topping"
aria-label="Select your favorite pizza topping..."
defaultValue=""
required
aria-invalid="true"
>
<option disabled value="">
Select your favorite pizza topping...
</option>
<option>Pepperoni</option>
<option>Mushrooms</option>
<option>Onions</option>
<option>Green Peppers</option>
<option>Olives</option>
</select>
<small>Please select your favorite pizza topping!</small>
<Code as="footer">{`<select aria-invalid="false">
...
</select>
<small>Great choice!</small>
<select required aria-invalid="true">
...
</select>
<small>
Please select your favorite pizza topping!
</small>`}</Code>
</article>
</section>
<section ref={dropdownRef}>
<Heading level={2} anchor="dropdown">
Dropdown
</Heading>
<p>
The dropdown component allows you to build a custom select with the same style as the
native select. See <Link to="/docs/dropdown">Dropdown</Link>.
</p>
<article aria-label="Dropdowns as selects" className="component">
<div className="grid">
<details className="dropdown">
<summary>Select your favorite French dessert...</summary>
<ul>
<li>
<label>
<input type="radio" name="french-dessert" value="Crème brûlée" />
Crème brûlée
</label>
</li>
<li>
<label>
<input type="radio" name="french-dessert" value="Macarons" />
Macarons
</label>
</li>
<li>
<label>
<input type="radio" name="french-dessert" value="Tarte tatin" />
Tarte tatin
</label>
</li>
<li>
<label>
<input type="radio" name="french-dessert" value="Éclair" />
Éclair
</label>
</li>
</ul>
</details>
</div>
</article>
</section>
{/* Edit on GitHub */}
<EditOnGithub file="docs.forms.select.jsx" />
</Content>
</>
);
}