Skip to content

Commit 71aead7

Browse files
committed
fix: add helper text for better announcement
1 parent a9e2760 commit 71aead7

File tree

1 file changed

+8
-2
lines changed
  • packages/shared/widget-plugin-filtering/src/controls/tag-picker

1 file changed

+8
-2
lines changed

packages/shared/widget-plugin-filtering/src/controls/tag-picker/TagPicker.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cn from "classnames";
22
import { useCombobox, UseComboboxProps, useMultipleSelection, UseMultipleSelectionProps } from "downshift";
33
import { observer } from "mobx-react-lite";
4-
import { createElement, useRef } from "react";
4+
import { createElement, useId, useRef } from "react";
55
import { OptionWithState } from "../../typings/OptionWithState";
66
import { ClearButton } from "../base/ClearButton";
77
import { OptionsWrapper } from "../base/OptionsWrapper";
@@ -30,6 +30,7 @@ const cls = classes();
3030

3131
// eslint-disable-next-line prefer-arrow-callback
3232
export const TagPicker = observer(function TagPicker(props: TagPickerProps): React.ReactElement {
33+
const [inputContainerId, helperText1] = [useId(), useId()];
3334
const { showCheckboxes, selectedStyle = "boxes", ariaLabel: inputLabel = "Search" } = props;
3435
const inputRef = useRef<HTMLInputElement>(null);
3536
const { getSelectedItemProps, getDropdownProps, removeSelectedItem } = useMultipleSelection(
@@ -57,7 +58,11 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
5758
data-empty={props.empty ? true : undefined}
5859
style={props.style}
5960
>
61+
<span id={helperText1} className="sr-only">
62+
Current filter values:
63+
</span>
6064
<div
65+
id={inputContainerId}
6166
className={cls.inputContainer}
6267
onClick={event => {
6368
if (event.currentTarget === event.target) {
@@ -92,7 +97,8 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
9297
onBlur: props.onBlur,
9398
onFocus: props.onFocus,
9499
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}`
96102
})}
97103
/>
98104
</div>

0 commit comments

Comments
 (0)