Skip to content

Commit 1cfed0b

Browse files
authored
fix: relax a11y "no redundant role" rule for li, ul, ol (#8867)
fixes #8854
1 parent 876f894 commit 1cfed0b

File tree

4 files changed

+16
-43
lines changed

4 files changed

+16
-43
lines changed

.changeset/pretty-tools-whisper.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: relax a11y "no redundant role" rule for li, ul, ol

packages/svelte/src/compiler/compile/nodes/Element.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,11 @@ export default class Element extends Node {
694694
);
695695
}
696696
// no-redundant-roles
697-
if (current_role === get_implicit_role(this.name, attribute_map)) {
697+
if (
698+
current_role === get_implicit_role(this.name, attribute_map) &&
699+
// <ul role="list"> is ok because CSS list-style:none removes the semantics and this is a way to bring them back
700+
!['ul', 'ol', 'li'].includes(this.name)
701+
) {
698702
component.warn(
699703
attribute,
700704
compiler_warnings.a11y_no_redundant_roles(current_role)

packages/svelte/test/validator/samples/a11y-no-redundant-roles/input.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
<h5 role="heading">heading</h5>
2020
<h6 role="heading">heading</h6>
2121
<hr role="separator" />
22-
<li role="listitem" />
22+
<!-- <li role="listitem" /> allowed since CSS list-style none removes semantic meaning and role brings it back -->
2323
<link role="link" />
24-
<main role="main"></main>
24+
<main role="main" />
2525
<menu role="list" />
2626
<nav role="navigation" />
27-
<ol role="list" />
27+
<!-- <ol role="list" /> allowed, see comment above -->
2828
<optgroup role="group" />
2929
<option role="option" />
3030
<output role="status" />
@@ -37,11 +37,11 @@
3737
<tfoot role="rowgroup" />
3838
<thead role="rowgroup" />
3939
<tr role="row" />
40-
<ul role="list" />
40+
<!--<ul role="list" /> allowed, see comment above -->
4141

4242
<!-- Tested header/footer not nested in section/article -->
43-
<header role="banner"></header>
44-
<footer role="contentinfo"></footer>
43+
<header role="banner" />
44+
<footer role="contentinfo" />
4545

4646
<!-- Allowed -->
4747
<!-- svelte-ignore a11y-no-noninteractive-element-to-interactive-role -->

packages/svelte/test/validator/samples/a11y-no-redundant-roles/warnings.json

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,6 @@
251251
"line": 21
252252
}
253253
},
254-
{
255-
"code": "a11y-no-redundant-roles",
256-
"end": {
257-
"column": 19,
258-
"line": 22
259-
},
260-
"message": "A11y: Redundant role 'listitem'",
261-
"start": {
262-
"column": 4,
263-
"line": 22
264-
}
265-
},
266254
{
267255
"code": "a11y-no-redundant-roles",
268256
"end": {
@@ -311,18 +299,6 @@
311299
"line": 26
312300
}
313301
},
314-
{
315-
"code": "a11y-no-redundant-roles",
316-
"end": {
317-
"column": 15,
318-
"line": 27
319-
},
320-
"message": "A11y: Redundant role 'list'",
321-
"start": {
322-
"column": 4,
323-
"line": 27
324-
}
325-
},
326302
{
327303
"code": "a11y-no-redundant-roles",
328304
"end": {
@@ -467,18 +443,6 @@
467443
"line": 39
468444
}
469445
},
470-
{
471-
"code": "a11y-no-redundant-roles",
472-
"end": {
473-
"column": 15,
474-
"line": 40
475-
},
476-
"message": "A11y: Redundant role 'list'",
477-
"start": {
478-
"column": 4,
479-
"line": 40
480-
}
481-
},
482446
{
483447
"code": "a11y-no-redundant-roles",
484448
"end": {

0 commit comments

Comments
 (0)