Skip to content

Commit 8499a01

Browse files
committed
fix: rewrite to aria-label instead of using value on input
1 parent f6dab3c commit 8499a01

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export function MultiSelection({
4040
const inputLabel = getInputLabel(options.inputId);
4141
const errorId = getValidationErrorId(options.inputId);
4242
const hasLabel = useMemo(() => Boolean(inputLabel), [inputLabel]);
43+
const labelText = inputLabel?.textContent?.trim() || "";
4344
const inputProps = getInputProps({
4445
...getDropdownProps(
4546
{
@@ -140,9 +141,19 @@ export function MultiSelection({
140141
tabIndex={tabIndex}
141142
placeholder=" "
142143
{...inputProps}
143-
aria-labelledby={hasLabel ? inputProps["aria-labelledby"] : undefined}
144+
aria-label={
145+
!isOpen && selectedItems.length > 0 && hasLabel
146+
? `${labelText}, ${selectedItems.map(id => selector.caption.get(id)).join(", ")}`
147+
: !isOpen && selectedItems.length > 0
148+
? selectedItems.map(id => selector.caption.get(id)).join(", ")
149+
: !hasLabel
150+
? options.ariaLabel
151+
: undefined
152+
}
153+
aria-labelledby={hasLabel && isOpen ? inputProps["aria-labelledby"] : undefined}
144154
aria-describedby={selector.validation ? errorId : undefined}
145155
aria-invalid={selector.validation ? true : undefined}
156+
aria-busy={selector.options.isLoading || undefined}
146157
/>
147158
<InputPlaceholder isEmpty={selectedItems.length <= 0}>{memoizedselectedCaptions}</InputPlaceholder>
148159
</div>

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function SingleSelection({
6060
const inputLabel = getInputLabel(options.inputId);
6161
const errorId = getValidationErrorId(options.inputId);
6262
const hasLabel = useMemo(() => Boolean(inputLabel), [inputLabel]);
63+
const labelText = inputLabel?.textContent?.trim() || "";
6364
const onInputKeyDown = useMemo<KeyboardEventHandler<HTMLInputElement> | undefined>(() => {
6465
if (!selector.clearable) {
6566
return undefined;
@@ -107,9 +108,19 @@ export function SingleSelection({
107108
tabIndex={tabIndex}
108109
{...inputProps}
109110
placeholder=" "
110-
aria-labelledby={hasLabel ? inputProps["aria-labelledby"] : undefined}
111+
aria-label={
112+
!isOpen && selectedItem && hasLabel
113+
? `${labelText}, ${selector.caption.get(selectedItem)}`
114+
: !isOpen && selectedItem
115+
? selector.caption.get(selectedItem)
116+
: !hasLabel
117+
? options.ariaLabel
118+
: undefined
119+
}
120+
aria-labelledby={hasLabel && isOpen ? inputProps["aria-labelledby"] : undefined}
111121
aria-describedby={selector.validation ? errorId : undefined}
112122
aria-invalid={selector.validation ? true : undefined}
123+
aria-busy={selector.options.isLoading || undefined}
113124
/>
114125
<InputPlaceholder
115126
isEmpty={!selector.currentId || !selector.caption.render(selectedItem, "label")}

0 commit comments

Comments
 (0)