|
1 | 1 | import cn from "classnames"; |
2 | 2 | import { useCombobox, UseComboboxProps, useMultipleSelection, UseMultipleSelectionProps } from "downshift"; |
3 | 3 | import { observer } from "mobx-react-lite"; |
4 | | -import { createElement, useRef } from "react"; |
| 4 | +import { createElement, useId, useRef } from "react"; |
5 | 5 | import { OptionWithState } from "../../typings/OptionWithState"; |
6 | 6 | import { ClearButton } from "../base/ClearButton"; |
7 | 7 | import { OptionsWrapper } from "../base/OptionsWrapper"; |
@@ -30,6 +30,7 @@ const cls = classes(); |
30 | 30 |
|
31 | 31 | // eslint-disable-next-line prefer-arrow-callback |
32 | 32 | export const TagPicker = observer(function TagPicker(props: TagPickerProps): React.ReactElement { |
| 33 | + const [inputContainerId, helperText1] = [useId(), useId()]; |
33 | 34 | const { showCheckboxes, selectedStyle = "boxes", ariaLabel: inputLabel = "Search" } = props; |
34 | 35 | const inputRef = useRef<HTMLInputElement>(null); |
35 | 36 | const { getSelectedItemProps, getDropdownProps, removeSelectedItem } = useMultipleSelection( |
@@ -57,7 +58,11 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea |
57 | 58 | data-empty={props.empty ? true : undefined} |
58 | 59 | style={props.style} |
59 | 60 | > |
| 61 | + <span id={helperText1} className="sr-only"> |
| 62 | + Current filter values: |
| 63 | + </span> |
60 | 64 | <div |
| 65 | + id={inputContainerId} |
61 | 66 | className={cls.inputContainer} |
62 | 67 | onClick={event => { |
63 | 68 | if (event.currentTarget === event.target) { |
@@ -92,7 +97,8 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea |
92 | 97 | onBlur: props.onBlur, |
93 | 98 | onFocus: props.onFocus, |
94 | 99 | placeholder: props.empty ? props.inputPlaceholder : undefined, |
95 | | - ...getDropdownProps({ preventKeyAction: isOpen, ref: inputRef }) |
| 100 | + ...getDropdownProps({ preventKeyAction: isOpen, ref: inputRef }), |
| 101 | + "aria-describedby": props.empty ? undefined : `${helperText1} ${inputContainerId}` |
96 | 102 | })} |
97 | 103 | /> |
98 | 104 | </div> |
|
0 commit comments