@@ -4,6 +4,7 @@ import { ClearButton } from "../../assets/icons";
44import { MultiSelector , SelectionBaseProps } from "../../helpers/types" ;
55import { getSelectedCaptionsPlaceholder } from "../../helpers/utils" ;
66import { useDownshiftMultiSelectProps } from "../../hooks/useDownshiftMultiSelectProps" ;
7+ import { useHasLabel } from "../../hooks/useHasLabel" ;
78import { useLazyLoading } from "../../hooks/useLazyLoading" ;
89import { ComboboxWrapper } from "../ComboboxWrapper" ;
910import { InputPlaceholder } from "../Placeholder" ;
@@ -37,6 +38,34 @@ export function MultiSelection({
3738 const inputRef = useRef < HTMLInputElement > ( null ) ;
3839 const isSelectedItemsBoxStyle = selector . selectedItemsStyle === "boxes" ;
3940 const isOptionsSelected = selector . isOptionsSelected ( ) ;
41+ const inputProps = getInputProps ( {
42+ ...getDropdownProps (
43+ {
44+ preventKeyAction : isOpen
45+ } ,
46+ { suppressRefError : true }
47+ ) ,
48+ ref : inputRef ,
49+ onKeyDown : ( event : KeyboardEvent ) => {
50+ if (
51+ ( event . key === "Backspace" && inputRef . current ?. selectionStart === 0 ) ||
52+ ( event . key === "ArrowLeft" && isSelectedItemsBoxStyle && inputRef . current ?. selectionStart === 0 )
53+ ) {
54+ setActiveIndex ( selectedItems . length - 1 ) ;
55+ }
56+ if ( event . key === " " ) {
57+ if ( highlightedIndex >= 0 ) {
58+ toggleSelectedItem ( highlightedIndex ) ;
59+ event . preventDefault ( ) ;
60+ event . stopPropagation ( ) ;
61+ }
62+ }
63+ } ,
64+ disabled : selector . readOnly ,
65+ readOnly : selector . options . filterType === "none" ,
66+ "aria-required" : ariaRequired . value
67+ } ) ;
68+ const hasLabel = useHasLabel ( inputProps . id ) ;
4069
4170 const memoizedselectedCaptions = useMemo (
4271 ( ) => getSelectedCaptionsPlaceholder ( selector , selectedItems ) ,
@@ -106,35 +135,8 @@ export function MultiSelection({
106135 } ) }
107136 tabIndex = { tabIndex }
108137 placeholder = " "
109- { ...getInputProps ( {
110- ...getDropdownProps (
111- {
112- preventKeyAction : isOpen
113- } ,
114- { suppressRefError : true }
115- ) ,
116- ref : inputRef ,
117- onKeyDown : ( event : KeyboardEvent ) => {
118- if (
119- ( event . key === "Backspace" && inputRef . current ?. selectionStart === 0 ) ||
120- ( event . key === "ArrowLeft" &&
121- isSelectedItemsBoxStyle &&
122- inputRef . current ?. selectionStart === 0 )
123- ) {
124- setActiveIndex ( selectedItems . length - 1 ) ;
125- }
126- if ( event . key === " " ) {
127- if ( highlightedIndex >= 0 ) {
128- toggleSelectedItem ( highlightedIndex ) ;
129- event . preventDefault ( ) ;
130- event . stopPropagation ( ) ;
131- }
132- }
133- } ,
134- disabled : selector . readOnly ,
135- readOnly : selector . options . filterType === "none" ,
136- "aria-required" : ariaRequired . value
137- } ) }
138+ { ...inputProps }
139+ aria-labelledby = { hasLabel ? inputProps [ "aria-labelledby" ] : undefined }
138140 />
139141 < InputPlaceholder isEmpty = { selectedItems . length <= 0 } > { memoizedselectedCaptions } </ InputPlaceholder >
140142 </ div >
0 commit comments