Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/quiet-selectors-control-mounted-listboxes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@astryxdesign/core': patch
---

[fix] Omit `aria-controls` from a closed Selector until its lazy listbox is mounted,
preventing an invalid ARIA reference on initial render while preserving the
combobox relationship whenever the popup is expanded.

@light-merlin-dark
15 changes: 15 additions & 0 deletions packages/core/src/Selector/Selector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,21 @@ describe('Selector', () => {
});

describe('keyboard accessibility', () => {
it('does not reference the listbox before the popup is mounted', async () => {
const user = userEvent.setup();
render(<Selector label="Fruit" options={OPTIONS} />);

const trigger = screen.getByRole('combobox');
expect(trigger).not.toHaveAttribute('aria-controls');

await user.click(trigger);
const listbox = screen.getByRole('listbox', h);
expect(trigger).toHaveAttribute('aria-controls', listbox.id);

await user.keyboard('{Escape}');
expect(trigger).not.toHaveAttribute('aria-controls');
});

it('trigger is focusable via Tab when enabled', async () => {
const user = userEvent.setup();
render(<Selector label="Fruit" options={OPTIONS} />);
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/Selector/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,10 @@ export function Selector<T extends SelectorOptionType>(
{...rest}
aria-haspopup="listbox"
aria-expanded={popover.isOpen}
aria-controls={listboxId}
// The listbox is lazy-mounted on first open. Do not reference an
// absent element from the initial closed trigger; axe treats that as
// an invalid critical ARIA relationship.
aria-controls={popover.isOpen ? listboxId : undefined}
aria-activedescendant={
!hasSearch && popover.isOpen && highlightedIndex >= 0
? getItemId(highlightedIndex)
Expand Down