@@ -4,7 +4,7 @@ title: Autocomplete
44status : Alpha
55description : Used to render a text input that allows a user to quickly filter through a list of options to pick one or more values.
66source : https://github.com/primer/react/tree/main/src/Autocomplete
7- storybook : ' /react/storybook?path=/story/forms- autocomplete--single-select '
7+ storybook : ' /react/storybook?path=/story/form-controls- autocomplete--default '
88---
99
1010import {Autocomplete } from ' @primer/react'
@@ -56,7 +56,7 @@ A function may be passed to the `filterFn` prop if this default filtering behavi
5656
5757``` jsx live
5858< FormControl>
59- < FormControl .Label > Pick a branch< / FormControl .Label >
59+ < FormControl .Label id = " autocompleteLabel-basic " > Pick a branch< / FormControl .Label >
6060 < Autocomplete>
6161 < Autocomplete .Input / >
6262 < Autocomplete .Overlay >
@@ -72,6 +72,7 @@ A function may be passed to the `filterFn` prop if this default filtering behavi
7272 {text: ' visual-design-tweaks' , id: 7 }
7373 ]}
7474 selectedItemIds= {[]}
75+ aria- labelledby= " autocompleteLabel-basic"
7576 / >
7677 < / Autocomplete .Overlay >
7778 < / Autocomplete>
@@ -114,7 +115,7 @@ const CustomTextInputExample = () => {
114115
115116 return (
116117 < FormControl>
117- < FormControl .Label > Pick options< / FormControl .Label >
118+ < FormControl .Label id = " autocompleteLabel-customInput " > Pick options< / FormControl .Label >
118119 < Autocomplete>
119120 < Autocomplete .Input as= {TextInputWithTokens} tokens= {tokens} onTokenRemove= {onTokenRemove} / >
120121 < Autocomplete .Overlay >
@@ -132,6 +133,7 @@ const CustomTextInputExample = () => {
132133 selectedItemIds= {selectedItemIds}
133134 onSelectedChange= {onSelectedChange}
134135 selectionVariant= " multiple"
136+ aria- labelledby= " autocompleteLabel-customInput"
135137 / >
136138 < / Autocomplete .Overlay >
137139 < / Autocomplete>
@@ -146,7 +148,7 @@ render(<CustomTextInputExample />)
146148
147149``` jsx live
148150< FormControl>
149- < FormControl .Label > Pick a branch< / FormControl .Label >
151+ < FormControl .Label id = " autocompleteLabel-withoutOverlay " > Pick a branch< / FormControl .Label >
150152 < Autocomplete>
151153 < Autocomplete .Input / >
152154 < Autocomplete .Menu
@@ -161,6 +163,7 @@ render(<CustomTextInputExample />)
161163 {text: ' visual-design-tweaks' , id: 7 }
162164 ]}
163165 selectedItemIds= {[]}
166+ aria- labelledby= " autocompleteLabel-withoutOverlay"
164167 / >
165168 < / Autocomplete>
166169< / FormControl>
@@ -221,7 +224,7 @@ const CustomRenderedItemExample = () => {
221224
222225 return (
223226 < FormControl>
224- < FormControl .Label > Pick labels< / FormControl .Label >
227+ < FormControl .Label id = " autocompleteLabel-customRenderedItem " > Pick labels< / FormControl .Label >
225228 < Autocomplete>
226229 < Autocomplete .Input
227230 as= {TextInputWithTokens}
@@ -248,7 +251,7 @@ const CustomRenderedItemExample = () => {
248251 selectedItemIds= {selectedItemIds}
249252 onSelectedChange= {onSelectedChange}
250253 selectionVariant= " multiple"
251- aria- labelledby= " autocompleteLabel-issueLabels "
254+ aria- labelledby= " autocompleteLabel-customRenderedItem "
252255 / >
253256 < / Autocomplete .Overlay >
254257 < / Autocomplete>
@@ -279,9 +282,9 @@ const CustomSortAfterMenuClose = () => {
279282
280283 return (
281284 < FormControl>
282- < FormControl .Label > Pick branches< / FormControl .Label >
285+ < FormControl .Label id = " autocompleteLabel-sortAfterClose " > Pick branches< / FormControl .Label >
283286 < Autocomplete>
284- < Autocomplete .Input id = " autocompleteInput-sortAfterClose " / >
287+ < Autocomplete .Input / >
285288 < Autocomplete .Overlay >
286289 < Autocomplete .Menu
287290 items= {[
@@ -323,9 +326,9 @@ const CustomSearchFilter = () => {
323326
324327 return (
325328 < FormControl>
326- < FormControl .Label > Pick a branch< / FormControl .Label >
329+ < FormControl .Label id = " autocompleteLabel-customFilter " > Pick a branch< / FormControl .Label >
327330 < Autocomplete>
328- < Autocomplete .Input id = " autocompleteInput-customFilter " onChange= {handleChange} / >
331+ < Autocomplete .Input onChange= {handleChange} / >
329332 < Autocomplete .Overlay >
330333 < Autocomplete .Menu
331334 items= {[
@@ -382,7 +385,9 @@ const InOverlayWithCustomScrollContainerRef = () => {
382385 )}
383386 >
384387 < FormControl>
385- < FormControl .Label visuallyHidden> Pick branches< / FormControl .Label >
388+ < FormControl .Label visuallyHidden id= " autocompleteLabel-withCustomScrollRef" >
389+ Pick branches
390+ < / FormControl .Label >
386391 < Autocomplete>
387392 < Box display= " flex" flexDirection= " column" height= " 100%" >
388393 < Box
@@ -424,7 +429,7 @@ const InOverlayWithCustomScrollContainerRef = () => {
424429 ]}
425430 selectedItemIds= {[]}
426431 customScrollContainerRef= {scrollContainerRef}
427- aria- labelledby= " autocompleteLabel"
432+ aria- labelledby= " autocompleteLabel-withCustomScrollRef "
428433 / >
429434 < / Box>
430435 < / Box>
@@ -465,14 +470,14 @@ const MultiSelect = () => {
465470 return (
466471 < Box display= " flex" flexDirection= " column" sx= {{gap: ' 1em' }}>
467472 < FormControl>
468- < FormControl .Label > Pick branches< / FormControl .Label >
473+ < FormControl .Label id = " autocompleteLabel-multiselect " > Pick branches< / FormControl .Label >
469474 < Autocomplete>
470- < Autocomplete .Input id = " autocompleteInput " / >
475+ < Autocomplete .Input / >
471476 < Autocomplete .Overlay >
472477 < Autocomplete .Menu
473478 items= {items}
474479 selectedItemIds= {selectedItemIds}
475- aria- labelledby= " autocompleteLabel"
480+ aria- labelledby= " autocompleteLabel-multiselect "
476481 onSelectedChange= {onSelectedChange}
477482 selectionVariant= " multiple"
478483 / >
@@ -535,9 +540,9 @@ const MultiSelectAddNewItem = () => {
535540 return (
536541 < Box display= " flex" flexDirection= " column" sx= {{gap: ' 1em' }}>
537542 < FormControl>
538- < FormControl .Label > Pick or add branches< / FormControl .Label >
543+ < FormControl .Label id = " autocompleteLabel-addItem " > Pick or add branches< / FormControl .Label >
539544 < Autocomplete>
540- < Autocomplete .Input onChange= {handleChange} id = " autocompleteInput " / >
545+ < Autocomplete .Input onChange= {handleChange} / >
541546 < Autocomplete .Overlay >
542547 < Autocomplete .Menu
543548 addNewItem= {
@@ -559,7 +564,7 @@ const MultiSelectAddNewItem = () => {
559564 selectedItemIds= {selectedItemIds}
560565 onSelectedChange= {onSelectedChange}
561566 selectionVariant= " multiple"
562- aria- labelledby= " autocompleteLabel"
567+ aria- labelledby= " autocompleteLabel-addItem "
563568 / >
564569 < / Autocomplete .Overlay >
565570 < / Autocomplete>
0 commit comments