An open source design system that's fully customizable and agent ready
TypeScript
fix(core): keep List semantics for all listStyle variants (#4369)
Baraa Hamodia17db1ab97ac
diff --git a/.changeset/a11y-list-role.md b/.changeset/a11y-list-role.mdnew file mode 100644index 0000000000..6b8555c843--- /dev/null+++ b/.changeset/a11y-list-role.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] List: keep list semantics for all listStyle variants by always emitting an explicit role="list", since the base style strips list-style-type for every variant and Safari/VoiceOver drops implicit list roles for such lists (WCAG 1.3.1)+@bhamodidiff --git a/packages/core/src/List/List.test.tsx b/packages/core/src/List/List.test.tsxindex aace5c0388..c159ae7242 100644--- a/packages/core/src/List/List.test.tsx+++ b/packages/core/src/List/List.test.tsx@@ -136,35 +136,23 @@ describe('List', () => {expect(container.querySelector('ul')).toBeInTheDocument();});- it('adds role="list" when listStyle is none (Safari fix)', () => {- const {container} = render(- <List>- <ListItem label="Item" />- </List>,- );- const ul = container.querySelector('ul');- expect(ul).toHaveAttribute('role', 'list');- });-- it('does not add role="list" when listStyle is disc', () => {- const {container} = render(- <List listStyle="disc">- <ListItem label="Item" />- </List>,- );- const ul = container.querySelector('ul');- expect(ul).not.toHaveAttribute('role');- });-- it('does not add role="list" when listStyle is decimal', () => {- const {container} = render(- <List listStyle="decimal">- <ListItem label="Item" />- </List>,- );- const ol = container.querySelector('ol');- expect(ol).not.toHaveAttribute('role');- });+ it.each(['none', 'disc', 'circle', 'decimal'] as const)(+ 'adds an explicit role="list" when listStyle is %s (Safari fix)',+ listStyle => {+ // The base list style always sets list-style-type: none (markers are+ // custom-rendered by ListItem), so Safari/VoiceOver drops the implicit+ // list role for EVERY variant — the explicit role must always be there.+ render(+ <List listStyle={listStyle}>+ <ListItem label="Item 1" />+ <ListItem label="Item 2" />+ </List>,+ );+ const list = screen.getByRole('list');+ expect(list).toHaveAttribute('role', 'list');+ expect(screen.getAllByRole('listitem')).toHaveLength(2);+ },+ );it('renders items as <li> elements', () => {const {container} = render(diff --git a/packages/core/src/List/List.tsx b/packages/core/src/List/List.tsxindex 09ad32207f..5af79dd793 100644--- a/packages/core/src/List/List.tsx+++ b/packages/core/src/List/List.tsx@@ -168,7 +168,12 @@ export function List({data-testid={testId}aria-labelledby={header != null ? headerId : undefined}{...(isOrdered && start != null && start !== 1 ? {start} : {})}- {...(listStyle === 'none' && !isOrdered ? {role: 'list'} : {})}+ // The base list style always sets list-style-type: none (markers are+ // custom-rendered by ListItem), and Safari/VoiceOver drops implicit+ // list semantics for lists styled with list-style: none. The explicit+ // role restores "list, N items" announcements for every listStyle+ // variant.+ role="list"{...mergeProps(themeProps('list', {density, listStyle}),stylex.props(