Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Selector, MultiSelector): hide standalone divider from a11y tree (#5107)

Ojas Mutreja405f1eed31a4
diff --git a/.changeset/selector-divider-listbox-violation.md b/.changeset/selector-divider-listbox-violation.md
new file mode 100644
index 0000000000..bb1172e2b6
--- /dev/null
+++ b/.changeset/selector-divider-listbox-violation.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `Selector` and `MultiSelector` no longer expose their `{type: 'divider'}` separators to assistive technology. `role="listbox"` only permits `option`/`group` children, but the divider previously rendered `role="separator"` as a direct child of the listbox (axe `aria-required-children`, impact critical). The divider is decorative and carries no information the options don't, so it's now hidden from the accessibility tree via `aria-hidden`, matching the pattern already used for section headings.
+
+@HelloOjasMutreja
diff --git a/packages/core/src/MultiSelector/MultiSelector.test.tsx b/packages/core/src/MultiSelector/MultiSelector.test.tsx
index 6376344bba..3dad467df7 100644
--- a/packages/core/src/MultiSelector/MultiSelector.test.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.test.tsx
@@ -1981,6 +1981,27 @@ describe('MultiSelector list structure', () => {
Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
});
+
+ it('hides a standalone divider from the accessibility tree (#4994)', async () => {
+ const user = userEvent.setup();
+ render(
+ <MultiSelector
+ label="Fruit"
+ options={['Apple', {type: 'divider'}, 'Banana']}
+ value={[]}
+ onChange={() => {}}
+ />,
+ );
+ await user.click(screen.getByRole('combobox'));
+
+ // role="listbox" only permits option/group children. The divider still
+ // renders role="separator" (unchanged visual/DOM), but must be excluded
+ // from the accessibility tree so it never reaches the listbox's exposed
+ // children (axe aria-required-children).
+ const divider = document.querySelector('[role="separator"]');
+ expect(divider).toBeTruthy();
+ expect(divider).toHaveAttribute('aria-hidden', 'true');
+ });
});
describe('MultiSelector search affordances', () => {
diff --git a/packages/core/src/MultiSelector/MultiSelector.tsx b/packages/core/src/MultiSelector/MultiSelector.tsx
index dc8fd74e94..ea58799625 100644
--- a/packages/core/src/MultiSelector/MultiSelector.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.tsx
@@ -1420,8 +1420,17 @@ export function MultiSelector<T extends MultiSelectorOptionType>({
// A standalone divider between groups would orphan itself once its
// neighbors are filtered out, so skip it while searching.
if (!isSearching) {
+ // role="listbox" only permits option/group children; the divider
+ // carries no information the options don't, so it's hidden from
+ // the accessibility tree entirely rather than exposing
+ // role="separator" as a disallowed listbox child (axe
+ // aria-required-children).
elements.push(
- <Divider key={`divider-${i}`} xstyle={styles.divider} />,
+ <Divider
+ key={`divider-${i}`}
+ aria-hidden="true"
+ xstyle={styles.divider}
+ />,
);
}
} else if (isSection(option)) {
diff --git a/packages/core/src/Selector/Selector.test.tsx b/packages/core/src/Selector/Selector.test.tsx
index b713e98eca..2a488e4464 100644
--- a/packages/core/src/Selector/Selector.test.tsx
+++ b/packages/core/src/Selector/Selector.test.tsx
@@ -2484,6 +2484,27 @@ describe('Selector section headings', () => {
// visible heading must not announce it a second time.
expect(heading).toHaveAttribute('aria-hidden', 'true');
});
+
+ it('hides a standalone divider from the accessibility tree (#4994)', async () => {
+ const user = userEvent.setup();
+ render(
+ <Selector
+ label="Fruit"
+ options={['Apple', {type: 'divider'}, 'Banana']}
+ value={undefined}
+ onChange={() => {}}
+ />,
+ );
+ await user.click(screen.getByRole('combobox'));
+
+ // role="listbox" only permits option/group children. The divider still
+ // renders role="separator" (unchanged visual/DOM), but must be excluded
+ // from the accessibility tree so it never reaches the listbox's exposed
+ // children (axe aria-required-children).
+ const divider = document.querySelector('[role="separator"]');
+ expect(divider).toBeTruthy();
+ expect(divider).toHaveAttribute('aria-hidden', 'true');
+ });
});
describe('Selector search focus ring', () => {
diff --git a/packages/core/src/Selector/Selector.tsx b/packages/core/src/Selector/Selector.tsx
index 91deaf45da..5ebc4cdd15 100644
--- a/packages/core/src/Selector/Selector.tsx
+++ b/packages/core/src/Selector/Selector.tsx
@@ -1344,7 +1344,17 @@ export function Selector<T extends SelectorOptionType>(
if (isSearching) {
continue;
}
- elements.push(<Divider key={`divider-${i}`} xstyle={styles.divider} />);
+ // role="listbox" only permits option/group children; the divider
+ // carries no information the options don't, so it's hidden from the
+ // accessibility tree entirely rather than exposing role="separator"
+ // as a disallowed listbox child (axe aria-required-children).
+ elements.push(
+ <Divider
+ key={`divider-${i}`}
+ aria-hidden="true"
+ xstyle={styles.divider}
+ />,
+ );
} else if (isSection(option)) {
const sectionItems: ReactNode[] = [];
for (const opt of option.options) {