Skip to content

Commit e960f27

Browse files
feat(combobox-web): add ariaLabel support for MultiSelection, and SingleSelection
1 parent 4d8db08 commit e960f27

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

packages/pluggableWidgets/combobox-web/src/Combobox.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default function Combobox(props: ComboboxContainerProps): ReactElement {
2525
noOptionsText: props.noOptionsText?.value,
2626
readOnlyStyle: props.readOnlyStyle,
2727
ariaRequired: props.ariaRequired,
28+
ariaLabel: props.ariaLabel?.value,
2829
a11yConfig: {
2930
ariaLabels: {
3031
clearSelection: props.clearButtonAriaLabel?.value ?? "",

packages/pluggableWidgets/combobox-web/src/components/MultiSelection/MultiSelection.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export function MultiSelection({
3737
const inputRef = useRef<HTMLInputElement>(null);
3838
const isSelectedItemsBoxStyle = selector.selectedItemsStyle === "boxes";
3939
const isOptionsSelected = selector.isOptionsSelected();
40+
const inputLabel = getInputLabel(options.inputId);
41+
const hasLabel = useMemo(() => Boolean(inputLabel), [inputLabel]);
4042
const inputProps = getInputProps({
4143
...getDropdownProps(
4244
{
@@ -62,12 +64,10 @@ export function MultiSelection({
6264
},
6365
disabled: selector.readOnly,
6466
readOnly: selector.options.filterType === "none",
65-
"aria-required": ariaRequired.value
67+
"aria-required": ariaRequired.value,
68+
"aria-label": !hasLabel && options.ariaLabel ? options.ariaLabel : undefined
6669
});
6770

68-
const inputLabel = getInputLabel(inputProps.id);
69-
const hasLabel = useMemo(() => Boolean(inputLabel), [inputLabel]);
70-
7171
const memoizedselectedCaptions = useMemo(
7272
() => getSelectedCaptionsPlaceholder(selector, selectedItems),
7373
[selector, selectedItems]

packages/pluggableWidgets/combobox-web/src/components/SingleSelection/SingleSelection.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,20 @@ export function SingleSelection({
5656
]
5757
);
5858

59+
const inputLabel = getInputLabel(options.inputId);
60+
const hasLabel = useMemo(() => Boolean(inputLabel), [inputLabel]);
61+
5962
const inputProps = getInputProps(
6063
{
6164
disabled: selector.readOnly,
6265
readOnly: selector.options.filterType === "none",
6366
ref: inputRef,
64-
"aria-required": ariaRequired.value
67+
"aria-required": ariaRequired.value,
68+
"aria-label": !hasLabel && options.ariaLabel ? options.ariaLabel : undefined
6569
},
6670
{ suppressRefError: true }
6771
);
6872

69-
const inputLabel = getInputLabel(inputProps.id);
70-
const hasLabel = useMemo(() => Boolean(inputLabel), [inputLabel]);
71-
7273
return (
7374
<Fragment>
7475
<ComboboxWrapper

packages/pluggableWidgets/combobox-web/src/helpers/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export interface SelectionBaseProps<Selector> {
100100
menuFooterContent?: ReactNode;
101101
tabIndex: number;
102102
ariaRequired: DynamicValue<boolean>;
103+
ariaLabel?: string;
103104
a11yConfig: {
104105
ariaLabels: {
105106
clearSelection: string;

0 commit comments

Comments
 (0)