Skip to content

Commit 56f3f3d

Browse files
authored
fix(FilterableMultiSelect): no aria-describedby helperText when invalid (#20738)
* fix(FilterableMultiSelect): no aria-describedby helperText when invalid * fix(filterablemultiselect): no aria-describedby helper text in warn
1 parent c178df2 commit 56f3f3d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/react/src/components/MultiSelect/FilterableMultiSelect.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,8 @@ export const FilterableMultiSelect = forwardRef(function FilterableMultiSelect<
880880
const inputProp = getInputProps(
881881
getDropdownProps({
882882
'aria-controls': isOpen ? menuId : undefined,
883-
'aria-describedby': helperText ? helperId : undefined,
883+
'aria-describedby':
884+
helperText && !invalid && !warn ? helperId : undefined,
884885
'aria-haspopup': 'listbox',
885886
// Remove excess aria `aria-labelledby`. HTML <label for>
886887
// provides this aria information.

packages/react/src/components/MultiSelect/__tests__/FilterableMultiSelect-test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,38 @@ describe('FilterableMultiSelect', () => {
512512
);
513513
});
514514

515+
it('should not apply aria-describedby helper text in invalid state', async () => {
516+
render(
517+
<FilterableMultiSelect
518+
{...mockProps}
519+
helperText="This is helper text"
520+
invalid
521+
invalidText="Something went wrong"
522+
/>
523+
);
524+
await waitForPosition();
525+
526+
const input = screen.getByRole('combobox');
527+
expect(input).not.toHaveAttribute('aria-describedby');
528+
expect(screen.getByText('Something went wrong')).toBeInTheDocument();
529+
});
530+
531+
it('should not apply aria-describedby helper text in warn state', async () => {
532+
render(
533+
<FilterableMultiSelect
534+
{...mockProps}
535+
helperText="This is helper text"
536+
warn
537+
warnText="Something might go wrong"
538+
/>
539+
);
540+
await waitForPosition();
541+
542+
const input = screen.getByRole('combobox');
543+
expect(input).not.toHaveAttribute('aria-describedby');
544+
expect(screen.getByText('Something might go wrong')).toBeInTheDocument();
545+
});
546+
515547
it('should handle itemToElement prop', async () => {
516548
const items = [{ text: 'test-item' }];
517549
const label = 'test-label';

0 commit comments

Comments
 (0)