Skip to content

Commit 4fe0ca2

Browse files
committed
Handle dynamic roles
1 parent 752aa35 commit 4fe0ca2

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/compiler/compile/nodes/Element.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,11 @@ export default class Element extends Node {
602602
}
603603
}
604604

605+
const has_dynamic_role = attribute_map.get('role') && !attribute_map.get('role').is_static;
606+
605607
// no-static-element-interactions
606-
// TODO: investigate footer
607-
// TODO: investigate dynamic roles
608608
if (
609+
!has_dynamic_role &&
609610
!is_hidden_from_screen_reader(this.name, attribute_map) &&
610611
!is_presentation_role(role) &&
611612
!is_interactive_element(this.name, attribute_map) &&

test/validator/samples/a11y-no-static-element-interactions/input.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
<script>
2+
const dynamicRole = "button";
3+
</script>
4+
15
<!-- valid -->
26
<button on:click={() => {}} />
37
<div on:keydown={() => {}} role="button" />
48
<input type="text" on:click={() => {}} />
59
<div on:copy={() => {}} />
610
<a href="/foo" on:click={() => {}}>link</a>
11+
<div role={dynamicRole} on:click={() => {}} />
712
<!-- invalid -->
813
<div on:keydown={() => {}} />
914
<!-- svelte-ignore a11y-missing-attribute -->

test/validator/samples/a11y-no-static-element-interactions/warnings.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
{
33
"code": "a11y-no-static-element-interactions",
44
"end": {
5-
"character": 249,
5+
"character": 347,
66
"column": 29,
7-
"line": 8
7+
"line": 13
88
},
99
"message": "A11y: <div> with keydown handler must have an ARIA role",
10-
"pos": 220,
10+
"pos": 318,
1111
"start": {
12-
"character": 220,
12+
"character": 318,
1313
"column": 0,
14-
"line": 8
14+
"line": 13
1515
}
1616
},
1717
{
1818
"code": "a11y-no-static-element-interactions",
1919
"end": {
20-
"character": 372,
20+
"character": 470,
2121
"column": 76,
22-
"line": 10
22+
"line": 15
2323
},
2424
"message": "A11y: <a> with mousedown, mouseup handlers must have an ARIA role",
25-
"pos": 296,
25+
"pos": 394,
2626
"start": {
27-
"character": 296,
27+
"character": 394,
2828
"column": 0,
29-
"line": 10
29+
"line": 15
3030
}
3131
}
3232
]

0 commit comments

Comments
 (0)