Skip to content

Commit 1f91227

Browse files
committed
fix: fix broken aria-controls issue
1 parent e71131e commit 1f91227

5 files changed

Lines changed: 61 additions & 19 deletions

File tree

packages/pluggableWidgets/combobox-web/src/__tests__/SingleSelection.spec.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ describe("Combo box (Association)", () => {
214214
expect(iconWrapper).toHaveAttribute("aria-hidden", "true");
215215
});
216216

217-
it("does not render menu list when closed", () => {
217+
it("hides menu list from assistive technologies when closed", () => {
218218
const component = render(<Combobox {...defaultProps} />);
219219
const menuList = component.container.querySelector(".widget-combobox-menu-list");
220-
expect(menuList).not.toBeInTheDocument();
220+
expect(menuList).toBeInTheDocument();
221+
expect(menuList).toHaveAttribute("aria-hidden", "true");
221222
});
222223

223224
it("renders menu list when open with items", async () => {
@@ -228,6 +229,7 @@ describe("Combo box (Association)", () => {
228229
await waitFor(() => {
229230
const menuList = component.container.querySelector(".widget-combobox-menu-list");
230231
expect(menuList).toBeInTheDocument();
232+
expect(menuList).not.toHaveAttribute("aria-hidden");
231233
expect(component.getAllByRole("option")).toHaveLength(4);
232234
});
233235
});
@@ -244,6 +246,7 @@ describe("Combo box (Association)", () => {
244246
await waitFor(() => {
245247
const menuList = component.container.querySelector(".widget-combobox-menu-list");
246248
expect(menuList).toBeInTheDocument();
249+
expect(menuList).not.toHaveAttribute("aria-hidden");
247250
const placeholder = component.container.querySelector(".widget-combobox-no-options");
248251
expect(placeholder).toBeInTheDocument();
249252
});

packages/pluggableWidgets/combobox-web/src/__tests__/__snapshots__/MultiSelection.spec.tsx.snap

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@ exports[`Combo box (Association) renders combobox widget 1`] = `
7979
<div
8080
class="widget-combobox-menu widget-combobox-menu-hidden"
8181
style="visibility: hidden; position: fixed;"
82-
/>
82+
>
83+
<ul
84+
aria-hidden="true"
85+
aria-labelledby="comboBox1-label"
86+
class="widget-combobox-menu-list"
87+
id="downshift-0-menu"
88+
role="listbox"
89+
/>
90+
</div>
8391
</div>
8492
</div>
8593
`;
@@ -163,7 +171,15 @@ exports[`Combo box (Association) toggles combobox menu on: input CLICK(focus) /
163171
<div
164172
class="widget-combobox-menu widget-combobox-menu-hidden"
165173
style="visibility: visible; position: fixed; width: 0px; top: 0px; left: 0px;"
166-
/>
174+
>
175+
<ul
176+
aria-hidden="true"
177+
aria-labelledby="comboBox1-label"
178+
class="widget-combobox-menu-list"
179+
id="downshift-0-menu"
180+
role="listbox"
181+
/>
182+
</div>
167183
</div>
168184
</div>
169185
`;
@@ -247,7 +263,15 @@ exports[`Combo box (Association) toggles combobox menu on: input TOGGLE BUTTON 1
247263
<div
248264
class="widget-combobox-menu widget-combobox-menu-hidden"
249265
style="visibility: hidden; position: fixed;"
250-
/>
266+
>
267+
<ul
268+
aria-hidden="true"
269+
aria-labelledby="comboBox1-label"
270+
class="widget-combobox-menu-list"
271+
id="downshift-0-menu"
272+
role="listbox"
273+
/>
274+
</div>
251275
</div>
252276
</div>
253277
`;

packages/pluggableWidgets/combobox-web/src/__tests__/__snapshots__/SingleSelection.spec.tsx.snap

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ exports[`Combo box (Association) renders combobox widget 1`] = `
8585
<div
8686
class="widget-combobox-menu widget-combobox-menu-hidden"
8787
style="visibility: hidden; position: fixed;"
88-
/>
88+
>
89+
<ul
90+
aria-hidden="true"
91+
aria-labelledby="comboBox1-label"
92+
class="widget-combobox-menu-list"
93+
id="downshift-0-menu"
94+
role="listbox"
95+
/>
96+
</div>
8997
</div>
9098
</div>
9199
`;

packages/pluggableWidgets/combobox-web/src/__tests__/__snapshots__/StaticSelection.spec.tsx.snap

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ exports[`Combo box (Static values) renders combobox widget 1`] = `
8585
<div
8686
class="widget-combobox-menu widget-combobox-menu-hidden"
8787
style="visibility: hidden; position: fixed;"
88-
/>
88+
>
89+
<ul
90+
aria-hidden="true"
91+
aria-labelledby="comboBox1-label"
92+
class="widget-combobox-menu-list"
93+
id="downshift-0-menu"
94+
role="listbox"
95+
/>
96+
</div>
8997
</div>
9098
</div>
9199
`;

packages/pluggableWidgets/combobox-web/src/components/ComboboxMenuWrapper.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,17 @@ export function ComboboxMenuWrapper(props: ComboboxMenuWrapperProps): ReactEleme
8282
{menuHeaderContent}
8383
</div>
8484
)}
85-
{isOpen && (
86-
<ul
87-
className={classNames("widget-combobox-menu-list", {
88-
"widget-combobox-menu-highlighted": (highlightedIndex ?? -1) >= 0,
89-
"widget-combobox-menu-lazy-scroll": lazyLoading && !isEmpty
90-
})}
91-
{...menuProps}
92-
>
93-
{isEmpty && !isLoading ? <NoOptionsPlaceholder>{noOptionsText}</NoOptionsPlaceholder> : children}
94-
{loader}
95-
</ul>
96-
)}
85+
<ul
86+
className={classNames("widget-combobox-menu-list", {
87+
"widget-combobox-menu-highlighted": (highlightedIndex ?? -1) >= 0,
88+
"widget-combobox-menu-lazy-scroll": lazyLoading && !isEmpty
89+
})}
90+
aria-hidden={!isOpen || undefined}
91+
{...menuProps}
92+
>
93+
{isOpen && (isEmpty && !isLoading ? <NoOptionsPlaceholder>{noOptionsText}</NoOptionsPlaceholder> : children)}
94+
{isOpen && loader}
95+
</ul>
9796
{isOpen && menuFooterContent && (
9897
<div tabIndex={0} className="widget-combobox-menu-footer" onMouseDown={PreventMenuCloseEventHandler}>
9998
{menuFooterContent}

0 commit comments

Comments
 (0)