From 1d135b44a87cc562134844c42ae9d6e1c84324e1 Mon Sep 17 00:00:00 2001 From: Sarah Higley Date: Mon, 30 Dec 2024 12:45:51 -0800 Subject: [PATCH 1/4] add aria-invalid to both Dropdown and Combobox --- packages/react/src/components/ComboBox/ComboBox.test.tsx | 9 +++++++++ packages/react/src/components/ComboBox/ComboBox.tsx | 3 +++ packages/react/src/components/Dropdown/Dropdown.base.tsx | 2 +- packages/react/src/components/Dropdown/Dropdown.test.tsx | 3 ++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/react/src/components/ComboBox/ComboBox.test.tsx b/packages/react/src/components/ComboBox/ComboBox.test.tsx index cd1c4eb315c519..235039068bf7c9 100644 --- a/packages/react/src/components/ComboBox/ComboBox.test.tsx +++ b/packages/react/src/components/ComboBox/ComboBox.test.tsx @@ -122,6 +122,15 @@ describe('ComboBox', () => { expect(combobox.getAttribute('aria-disabled')).toEqual('true'); }); + it('sets alert message and aria-invalid when errorMessage is set', () => { + const { getByRole } = render( + , + ); + const alert = getByRole('alert'); + expect(alert.textContent).toBe('This is an example error.'); + expect(getByRole('combobox').getAttribute('aria-invalid')).toBe('true'); + }); + it('Renders no selected item in default case', () => { const { getByRole } = render(); expect(getByRole('combobox').getAttribute('value')).toEqual(''); diff --git a/packages/react/src/components/ComboBox/ComboBox.tsx b/packages/react/src/components/ComboBox/ComboBox.tsx index 6e558e4fa347d2..e342c4b6798a35 100644 --- a/packages/react/src/components/ComboBox/ComboBox.tsx +++ b/packages/react/src/components/ComboBox/ComboBox.tsx @@ -646,6 +646,8 @@ class ComboBoxInternal extends React.Component 0 ? true : false; + return (
{ // If option is selected render title, otherwise render the placeholder text diff --git a/packages/react/src/components/Dropdown/Dropdown.test.tsx b/packages/react/src/components/Dropdown/Dropdown.test.tsx index f8a89af7a4ae05..dc2cfd17cfa653 100644 --- a/packages/react/src/components/Dropdown/Dropdown.test.tsx +++ b/packages/react/src/components/Dropdown/Dropdown.test.tsx @@ -710,12 +710,13 @@ describe('Dropdown', () => { expect(dropdownRoot.getAttribute('aria-labelledby')).not.toBeNull(); }); - it('sets role=error on included error message', () => { + it('sets alert message and aria-invalid when errorMessage is set', () => { const { getByRole } = render( , ); const alert = getByRole('alert'); expect(alert.textContent).toBe('This is an example error.'); + expect(getByRole('combobox').getAttribute('aria-invalid')).toBe('true'); }); }); From 077d70bc099a7dac2e7a2369e0a3256c3cbfae60 Mon Sep 17 00:00:00 2001 From: Sarah Higley Date: Mon, 30 Dec 2024 13:34:21 -0800 Subject: [PATCH 2/4] update snapshots --- .../ComboBox/__snapshots__/ComboBox.test.tsx.snap | 4 ++++ .../Dropdown/__snapshots__/Dropdown.test.tsx.snap | 8 ++++---- .../TimePicker/__snapshots__/TimePicker.test.tsx.snap | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/react/src/components/ComboBox/__snapshots__/ComboBox.test.tsx.snap b/packages/react/src/components/ComboBox/__snapshots__/ComboBox.test.tsx.snap index 3b70af4eeb29a7..0c88b4eb66d0d8 100644 --- a/packages/react/src/components/ComboBox/__snapshots__/ComboBox.test.tsx.snap +++ b/packages/react/src/components/ComboBox/__snapshots__/ComboBox.test.tsx.snap @@ -145,6 +145,7 @@ exports[`ComboBox Renders correctly 1`] = `