Skip to content

Commit

Permalink
fix(Combobox): improve screen reader experience for Select-Only combo…
Browse files Browse the repository at this point in the history
…box w NVDA (#1988)
  • Loading branch information
ze-flo authored Dec 12, 2024
1 parent abb6e98 commit f72c31f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/dropdowns.next/src/elements/combobox/Combobox.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,26 @@ describe('Combobox', () => {
expect(input).toHaveAttribute('aria-expanded', 'false');
});

it('sets the correct aria attributes on `ListBox` when expanded or collapsed', async () => {
const { getByTestId } = render(
<TestCombobox isAutocomplete>
<Option value="test" />
</TestCombobox>
);
const combobox = getByTestId('combobox');
const trigger = combobox.firstChild as HTMLElement;

await user.click(trigger);

const listbox = combobox.querySelector('[role="listbox"]') as HTMLElement;

expect(listbox).toHaveAttribute('aria-hidden', 'false');

await user.click(trigger);

expect(listbox).toHaveAttribute('aria-hidden', 'true');
});

it('retains expansion on `OptGroup` click', async () => {
const { getByTestId } = render(
<TestCombobox isAutocomplete>
Expand Down
4 changes: 4 additions & 0 deletions packages/dropdowns.next/src/elements/combobox/Listbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ export const Listbox = forwardRef<HTMLUListElement, IListboxProps>(
ref={floatingRef}
>
<StyledListbox
aria-hidden={
// Hide from NVDA when collapsed to prevent incorrect / missing announcements caused by animation
!isExpanded
}
isCompact={isCompact}
maxHeight={maxHeight}
minHeight={minHeight}
Expand Down

0 comments on commit f72c31f

Please sign in to comment.