From 85794f99b82ad26632f7805b95e7e66ea041fa9b Mon Sep 17 00:00:00 2001 From: Sarah Higley Date: Fri, 6 Jan 2023 12:52:24 -0800 Subject: [PATCH 1/4] fix: add aria-owns to combobox and dropdown root --- .../src/components/Combobox/Combobox.test.tsx | 12 ++++++++++++ .../Combobox/__snapshots__/Combobox.test.tsx.snap | 1 + .../src/components/Combobox/useCombobox.tsx | 3 ++- .../src/components/Dropdown/Dropdown.test.tsx | 13 +++++++++++++ .../Dropdown/__snapshots__/Dropdown.test.tsx.snap | 9 +++++---- .../src/components/Dropdown/useDropdown.tsx | 1 + .../src/utils/useTriggerListboxSlots.ts | 4 +++- 7 files changed, 37 insertions(+), 6 deletions(-) diff --git a/packages/react-components/react-combobox/src/components/Combobox/Combobox.test.tsx b/packages/react-components/react-combobox/src/components/Combobox/Combobox.test.tsx index 14003e83921ab7..e5ad059520970c 100644 --- a/packages/react-components/react-combobox/src/components/Combobox/Combobox.test.tsx +++ b/packages/react-components/react-combobox/src/components/Combobox/Combobox.test.tsx @@ -136,6 +136,18 @@ describe('Combobox', () => { expect(chevronButton?.getAttribute('aria-labelledby')).toEqual('testId'); }); + it('adds aria-owns pointing to the popup', () => { + const { getByRole, container } = render( + + + + + , + ); + const listboxId = getByRole('listbox').id; + expect(container.querySelector('.root')?.getAttribute('aria-owns')).toEqual(listboxId);\ + }); + /* open/close tests */ it('opens the popup on click', () => { const { getByRole } = render( diff --git a/packages/react-components/react-combobox/src/components/Combobox/__snapshots__/Combobox.test.tsx.snap b/packages/react-components/react-combobox/src/components/Combobox/__snapshots__/Combobox.test.tsx.snap index 62f751823dd848..a682e3698fe6e1 100644 --- a/packages/react-components/react-combobox/src/components/Combobox/__snapshots__/Combobox.test.tsx.snap +++ b/packages/react-components/react-combobox/src/components/Combobox/__snapshots__/Combobox.test.tsx.snap @@ -73,6 +73,7 @@ exports[`Combobox renders an open listbox 1`] = `
diff --git a/packages/react-components/react-combobox/src/components/Combobox/useCombobox.tsx b/packages/react-components/react-combobox/src/components/Combobox/useCombobox.tsx index 5f96757a5d0448..b75183962b59c7 100644 --- a/packages/react-components/react-combobox/src/components/Combobox/useCombobox.tsx +++ b/packages/react-components/react-combobox/src/components/Combobox/useCombobox.tsx @@ -44,7 +44,7 @@ export const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref { expect(container.querySelector('[role=listbox]')).not.toBeNull(); }); + it('adds aria-owns pointing to the popup', () => { + const { getByRole, container } = render( + + + + + , + ); + + const listboxId = getByRole('listbox').id; + expect(container.querySelector('.root')?.getAttribute('aria-owns')).toEqual(listboxId); + }); + /* open/close tests */ it('opens the popup on click', () => { const { getByRole } = render( diff --git a/packages/react-components/react-combobox/src/components/Dropdown/__snapshots__/Dropdown.test.tsx.snap b/packages/react-components/react-combobox/src/components/Dropdown/__snapshots__/Dropdown.test.tsx.snap index 7dcf6069bcc49f..74ee1175af7b74 100644 --- a/packages/react-components/react-combobox/src/components/Dropdown/__snapshots__/Dropdown.test.tsx.snap +++ b/packages/react-components/react-combobox/src/components/Dropdown/__snapshots__/Dropdown.test.tsx.snap @@ -40,7 +40,7 @@ exports[`Dropdown renders an open listbox 1`] = ` class="fui-Dropdown" >