Skip to content

Commit

Permalink
fix(#6130): Ignore HiddenSelect when tree walking (#6139)
Browse files Browse the repository at this point in the history
We should skip HiddenSelect element in Picker when tree walking to determine the next or previous focusable element. However, we should not use [data-a11y-ignore], which is used to exclude elements from aXe automated accessibility tests.

Co-authored-by: Daniel Lu <dl1644@gmail.com>
  • Loading branch information
majornista and LFDanLu authored Apr 6, 2024
1 parent 5d7bbd5 commit 24d931b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@react-aria/focus/src/isElementVisible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function isAttributeVisible(element: Element, childElement?: Element) {
return (
!element.hasAttribute('hidden') &&
// Ignore HiddenSelect when tree walking.
!(element.hasAttribute('data-a11y-ignore') && element.getAttribute('aria-hidden') === 'true') &&
!(element.hasAttribute('data-hidden-select-ignore') && element.getAttribute('aria-hidden') === 'true') &&
(element.nodeName === 'DETAILS' &&
childElement &&
childElement.nodeName !== 'SUMMARY'
Expand Down
1 change: 1 addition & 0 deletions packages/@react-aria/select/src/HiddenSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
containerProps: {
...visuallyHiddenProps,
'aria-hidden': true,
['data-hidden-select-ignore']: true,
['data-a11y-ignore']: 'aria-hidden-focus'
},
inputProps: {
Expand Down
8 changes: 8 additions & 0 deletions packages/@react-aria/select/test/HiddenSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,12 @@ describe('<HiddenSelect />', () => {

expect(screen.getByTestId('hidden-select-container')).toHaveAttribute('data-a11y-ignore', 'aria-hidden-focus');
});

it('should always add a data attribute data-hidden-select-ignore', () => {
render(
<HiddenSelectExample items={makeItems(5)} />
);

expect(screen.getByTestId('hidden-select-container')).toHaveAttribute('data-hidden-select-ignore');
});
});

0 comments on commit 24d931b

Please sign in to comment.