@@ -12,10 +12,10 @@ A list of items used to show autocompleted results. Use the [`<auto-complete>`](
12
12
13
13
``` html live
14
14
<div class =" position-relative" >
15
- <label class =" autocomplete-label-stacked" >Search by user</label >
15
+ <label for = " input-0 " class =" autocomplete-label-stacked" >Search by user</label >
16
16
<span class =" autocomplete-body" >
17
- <input class =" form-control" type =" text" />
18
- <ul class =" autocomplete-results" >
17
+ <input id = " input-0 " class =" form-control" type =" text" />
18
+ <ul role = " listbox " aria-label = " Results " class =" autocomplete-results" >
19
19
<li class =" autocomplete-item" aria-selected =" true" >Option 1</li >
20
20
<li class =" autocomplete-item" >Option 2</li >
21
21
<li class =" autocomplete-item" >Option 3</li >
@@ -36,10 +36,10 @@ A list of items used to show autocompleted results. Use the [`<auto-complete>`](
36
36
37
37
``` html live
38
38
<div class =" position-relative" >
39
- <label class =" autocomplete-label-inline" >Search by team</label >
39
+ <label for = " input-1 " class =" autocomplete-label-inline" >Search by team</label >
40
40
<span class =" autocomplete-body" >
41
- <input class =" form-control" type =" text" />
42
- <ul class =" autocomplete-results" >
41
+ <input id = " input-1 " class =" form-control" type =" text" />
42
+ <ul role = " listbox " aria-label = " Results " class =" autocomplete-results" >
43
43
<li class =" autocomplete-item" aria-selected =" true" >Team 1 (works on Ruby architecture)</li >
44
44
<li class =" autocomplete-item" >Team 2 (works on frontend JS architecture)</li >
45
45
<li class =" autocomplete-item" >Team 3 (this team works on design systems)</li >
@@ -56,11 +56,11 @@ A list of items used to show autocompleted results. Use the [`<auto-complete>`](
56
56
57
57
## Embedded icon with visible label
58
58
59
- Stacked label
59
+ ### Stacked label
60
60
61
61
``` html live
62
62
<div class =" position-relative" >
63
- <label class =" autocomplete-label-stacked" >Search by org</label >
63
+ <label for = " input-2 " class =" autocomplete-label-stacked" >Search by org</label >
64
64
<span class =" autocomplete-body" >
65
65
<div class =" form-control autocomplete-embedded-icon-wrap" >
66
66
<svg
@@ -76,9 +76,9 @@ Stacked label
76
76
d =" M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"
77
77
></path >
78
78
</svg >
79
- <input class =" form-control" type =" text" />
79
+ <input id = " input-2 " class =" form-control" type =" text" />
80
80
</div >
81
- <ul class =" autocomplete-results" >
81
+ <ul role = " listbox " aria-label = " Results " class =" autocomplete-results" >
82
82
<li class =" autocomplete-item" aria-selected =" true" >Option 1</li >
83
83
<li class =" autocomplete-item" >Option 2</li >
84
84
<li class =" autocomplete-item" >Option 3</li >
@@ -93,11 +93,11 @@ Stacked label
93
93
</style >
94
94
```
95
95
96
- Inline label
96
+ ### Inline label
97
97
98
98
``` html live
99
99
<div class =" position-relative" >
100
- <label class =" autocomplete-label-inline" >Search by org</label >
100
+ <label for = " input-3 " class =" autocomplete-label-inline" >Search by org</label >
101
101
<span class =" autocomplete-body" >
102
102
<div class =" form-control autocomplete-embedded-icon-wrap" >
103
103
<svg
@@ -113,9 +113,9 @@ Inline label
113
113
d =" M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"
114
114
></path >
115
115
</svg >
116
- <input class =" form-control" type =" text" />
116
+ <input id = " input-3 " class =" form-control" type =" text" />
117
117
</div >
118
- <ul class =" autocomplete-results" >
118
+ <ul role = " listbox " aria-label = " Results " class =" autocomplete-results" >
119
119
<li class =" autocomplete-item" aria-selected =" true" >Option 1</li >
120
120
<li class =" autocomplete-item" >Option 2</li >
121
121
<li class =" autocomplete-item" >Option 3</li >
@@ -134,7 +134,7 @@ Inline label
134
134
135
135
``` html live
136
136
<div class =" position-relative" >
137
- <label class =" autocomplete-label-stacked sr-only" >Search by org</label >
137
+ <label for = " input-4 " class =" autocomplete-label-stacked sr-only" >Search by org</label >
138
138
<span class =" autocomplete-body" >
139
139
<div class =" form-control autocomplete-embedded-icon-wrap" >
140
140
<svg
@@ -150,9 +150,9 @@ Inline label
150
150
d =" M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"
151
151
></path >
152
152
</svg >
153
- <input class =" form-control" type =" text" />
153
+ <input id = " input-4 " class =" form-control" type =" text" />
154
154
</div >
155
- <ul class =" autocomplete-results" >
155
+ <ul role = " listbox " aria-label = " Results " class =" autocomplete-results" >
156
156
<li class =" autocomplete-item" aria-selected =" true" >Option 1</li >
157
157
<li class =" autocomplete-item" >Option 2</li >
158
158
<li class =" autocomplete-item" >Option 3</li >
@@ -167,14 +167,183 @@ Inline label
167
167
</style >
168
168
```
169
169
170
+ ## Within form group
171
+
172
+ ``` html live
173
+ <div class =" form-group" >
174
+ <div class =" form-group-body" >
175
+ <div class =" position-relative" >
176
+ <label for =" input-5" class =" autocomplete-label-stacked" >Search by org</label >
177
+ <span class =" autocomplete-body" >
178
+ <div class =" form-control autocomplete-embedded-icon-wrap" >
179
+ <svg
180
+ class =" octicon"
181
+ aria-hidden =" true"
182
+ xmlns =" http://www.w3.org/2000/svg"
183
+ viewBox =" 0 0 16 16"
184
+ width =" 16"
185
+ height =" 16"
186
+ ><path
187
+ fill-rule =" evenodd"
188
+ d =" M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"
189
+ ></path ></svg >
190
+ <input id =" input-5" class =" form-control" type =" text" />
191
+ </div >
192
+ <ul role =" listbox" aria-label =" Results" class =" autocomplete-results" >
193
+ <li class =" autocomplete-item" aria-selected =" true" >Option 1</li >
194
+ <li class =" autocomplete-item" >Option 2</li >
195
+ <li class =" autocomplete-item" >Option 3</li >
196
+ </ul >
197
+ </span >
198
+ </div >
199
+ </div >
200
+ </div >
201
+
202
+ <style >
203
+ .frame-example {
204
+ height : 180px ;
205
+ }
206
+ </style >
207
+ ```
208
+
209
+ ## Within input group
210
+
211
+ When rendering ` Autocomplete ` with embedded icon within an [ input group] ( https://primer.style/css/components/forms#input-group ) , add ` .input-group-button--autocomplete-embedded-icon ` to ` .input-group-button ` .
212
+
213
+ ### Stacked
214
+
215
+ ``` html live
216
+ <div class =" input-group" >
217
+ <div class =" position-relative" >
218
+ <label for =" input-6" class =" autocomplete-label-stacked" >Search by org</label >
219
+ <span class =" autocomplete-body" >
220
+ <div class =" form-control autocomplete-embedded-icon-wrap" >
221
+ <svg
222
+ class =" octicon"
223
+ aria-hidden =" true"
224
+ xmlns =" http://www.w3.org/2000/svg"
225
+ viewBox =" 0 0 16 16"
226
+ width =" 16"
227
+ height =" 16"
228
+ ><path
229
+ fill-rule =" evenodd"
230
+ d =" M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"
231
+ ></path ></svg >
232
+ <input id =" input-6" class =" form-control" type =" text" />
233
+ </div >
234
+ <ul role =" listbox" aria-label =" Results" class =" autocomplete-results" >
235
+ <li class =" autocomplete-item" aria-selected =" true" >Option 1</li >
236
+ <li class =" autocomplete-item" >Option 2</li >
237
+ <li class =" autocomplete-item" >Option 3</li >
238
+ </ul >
239
+ </span >
240
+ </div >
241
+ <span class =" input-group-button input-group-button--autocomplete-embedded-icon" >
242
+ <button class =" btn" type =" button" aria-label =" Copy to clipboard" >
243
+ <svg class =" octicon octicon-clippy" viewBox =" 0 0 14 16" version =" 1.1" width =" 14" height =" 16" aria-hidden =" true" ><path fill-rule =" evenodd" d =" M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z" ></path ></svg >
244
+ </button >
245
+ </span >
246
+ </div >
247
+
248
+ <style >
249
+ .frame-example {
250
+ height : 180px ;
251
+ }
252
+ </style >
253
+ ```
254
+
255
+ ### Inline
256
+ ``` html live
257
+ <div class =" input-group" >
258
+ <div class =" position-relative" >
259
+ <label for =" input-7" class =" autocomplete-label-inline" >Search by org</label >
260
+ <span class =" autocomplete-body" >
261
+ <div class =" form-control autocomplete-embedded-icon-wrap" >
262
+ <svg
263
+ class =" octicon"
264
+ aria-hidden =" true"
265
+ xmlns =" http://www.w3.org/2000/svg"
266
+ viewBox =" 0 0 16 16"
267
+ width =" 16"
268
+ height =" 16"
269
+ ><path
270
+ fill-rule =" evenodd"
271
+ d =" M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"
272
+ ></path ></svg >
273
+ <input id =" input-7" class =" form-control" type =" text" />
274
+ </div >
275
+ <ul role =" listbox" aria-label =" Results" class =" autocomplete-results" >
276
+ <li class =" autocomplete-item" aria-selected =" true" >Option 1</li >
277
+ <li class =" autocomplete-item" >Option 2</li >
278
+ <li class =" autocomplete-item" >Option 3</li >
279
+ </ul >
280
+ </span >
281
+ </div >
282
+ <span class =" input-group-button input-group-button--autocomplete-embedded-icon" >
283
+ <button class =" btn" type =" button" aria-label =" Copy to clipboard" >
284
+ <svg class =" octicon octicon-clippy" viewBox =" 0 0 14 16" version =" 1.1" width =" 14" height =" 16" aria-hidden =" true" ><path fill-rule =" evenodd" d =" M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z" ></path ></svg >
285
+ </button >
286
+ </span >
287
+ </div >
288
+
289
+ <style >
290
+ .frame-example {
291
+ height : 160px ;
292
+ }
293
+ </style >
294
+ ```
295
+
296
+ ## Container with ` max-width `
297
+
298
+ ``` html live
299
+ <div class =" Box" style =" max-width : 440px ;" >
300
+ <div class =" Box-body" >
301
+ <div class =" form-group" >
302
+ <div class =" form-group-body" >
303
+ <div class =" position-relative" >
304
+ <label for =" input-8" class =" autocomplete-label-stacked" >Search by org</label >
305
+ <span class =" autocomplete-body" >
306
+ <div class =" form-control autocomplete-embedded-icon-wrap" >
307
+ <svg
308
+ class =" octicon"
309
+ aria-hidden =" true"
310
+ xmlns =" http://www.w3.org/2000/svg"
311
+ viewBox =" 0 0 16 16"
312
+ width =" 16"
313
+ height =" 16"
314
+ ><path
315
+ fill-rule =" evenodd"
316
+ d =" M11.5 7a4.499 4.499 0 11-8.998 0A4.499 4.499 0 0111.5 7zm-.82 4.74a6 6 0 111.06-1.06l3.04 3.04a.75.75 0 11-1.06 1.06l-3.04-3.04z"
317
+ ></path ></svg >
318
+ <input id =" input-8" class =" form-control" type =" text" />
319
+ </div >
320
+ <ul role =" listbox" aria-label =" Results" class =" autocomplete-results" >
321
+ <li class =" autocomplete-item" aria-selected =" true" >Option 1</li >
322
+ <li class =" autocomplete-item" >Option 2</li >
323
+ <li class =" autocomplete-item" >Option 3</li >
324
+ </ul >
325
+ </span >
326
+ </div >
327
+ </div >
328
+ </div >
329
+ </div >
330
+ </div >
331
+
332
+ <style >
333
+ .frame-example {
334
+ height : 220px ;
335
+ }
336
+ </style >
337
+ ```
338
+
170
339
## Additional content
171
340
172
341
Autocomplete items can contain additional content, like an ` .avatar ` . Or use utility classes to customize the text style.
173
342
174
343
``` html live
175
344
<div class =" position-relative" >
176
345
<input class =" form-control" type =" text" aria-label =" Search by user" placeholder =" Search by user" />
177
- <ul class =" autocomplete-results" >
346
+ <ul role = " listbox " aria-label = " Results " class =" autocomplete-results" >
178
347
<li class =" autocomplete-item" aria-selected =" true" >
179
348
<img src =" https://github.com/github.png" width =" 20" class =" avatar mr-1" alt =" " />
180
349
<span >GitHub Inc.</span >
@@ -210,7 +379,7 @@ The `.suggester` component is meant for showing suggestions while typing in a la
210
379
<textarea class =" form-control width-full" placeholder =" Leave a comment" aria-label =" Comment body" >
211
380
This is on top of #</textarea
212
381
>
213
- <ul class =" suggester suggester-container" role =" listbox" style =" top : 4px ; left : 125px ;" >
382
+ <ul aria-label = " Results " class =" suggester suggester-container" role =" listbox" style =" top : 4px ; left : 125px ;" >
214
383
<li aria-selected =" true" >
215
384
<svg
216
385
class =" octicon color-fg-subtle"
0 commit comments