Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(a11y): add click-events-have-key-events rule (#5073)
* feat(a11y): add click-events-have-key-events rule Signed-off-by: mhatvan <markus_hatvan@aon.at> * Fine-tune click-events-have-key-events rule Signed-off-by: mhatvan <markus_hatvan@aon.at> * Implement PR feedback Signed-off-by: Markus Hatvan <markus_hatvan@aon.at> * Implement PR feedback Signed-off-by: Markus Hatvan <markus_hatvan@aon.at> * slight refactor to use existing utils * update docs * fix rebase conflicts Signed-off-by: mhatvan <markus_hatvan@aon.at> Signed-off-by: Markus Hatvan <markus_hatvan@aon.at> Co-authored-by: tanhauhau <lhtan93@gmail.com> Co-authored-by: dsfx3d <dsfx3d@gmail.com>
- Loading branch information
1 parent
6469097
commit 82013aa
Showing
6 changed files
with
222 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test/validator/samples/a11y-click-events-have-key-events/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<script> | ||
function noop() {} | ||
let props = {}; | ||
const dynamicTypeValue = "checkbox"; | ||
const dynamicAriaHiddenValue = "false"; | ||
const dynamicRole = "button"; | ||
</script> | ||
|
||
<!-- should warn --> | ||
<div on:click={noop} /> | ||
<div on:click={noop} aria-hidden="false" /> | ||
|
||
<section on:click={noop} /> | ||
<main on:click={noop} /> | ||
<article on:click={noop} /> | ||
<header on:click={noop} /> | ||
<footer on:click={noop} /> | ||
|
||
<!-- should not warn --> | ||
<div class="foo" /> | ||
|
||
<a href="http://x.y.z" on:click={noop}>foo</a> | ||
<button on:click={noop} /> | ||
<select on:click={noop} /> | ||
|
||
<input type="button" on:click={noop} /> | ||
<input type={dynamicTypeValue} on:click={noop} /> | ||
|
||
<div on:click={noop} {...props} /> | ||
<div on:click={noop} on:keydown={noop} /> | ||
<div on:click={noop} on:keyup={noop} /> | ||
<div on:click={noop} on:keypress={noop} /> | ||
<div on:click={noop} on:keydown={noop} on:keyup={noop} /> | ||
<div on:click={noop} on:keyup={noop} on:keypress={noop} /> | ||
<div on:click={noop} on:keypress={noop} on:keydown={noop} /> | ||
<div on:click={noop} on:keydown={noop} on:keyup={noop} on:keypress={noop} /> | ||
|
||
<input on:click={noop} type="hidden" /> | ||
|
||
<div on:click={noop} aria-hidden /> | ||
<div on:click={noop} aria-hidden="true" /> | ||
<div on:click={noop} aria-hidden="false" on:keydown={noop} /> | ||
<div on:click={noop} aria-hidden={dynamicAriaHiddenValue} /> | ||
|
||
<div on:click={noop} role="presentation" /> | ||
<div on:click={noop} role="none" /> | ||
<div on:click={noop} role={dynamicRole} /> |
107 changes: 107 additions & 0 deletions
107
test/validator/samples/a11y-click-events-have-key-events/warnings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
[ | ||
{ | ||
"code": "a11y-click-events-have-key-events", | ||
"message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", | ||
"start": { | ||
"line": 12, | ||
"column": 0, | ||
"character": 190 | ||
}, | ||
"end": { | ||
"line": 12, | ||
"column": 23, | ||
"character": 213 | ||
}, | ||
"pos": 190 | ||
}, | ||
{ | ||
"code": "a11y-click-events-have-key-events", | ||
"message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", | ||
"start": { | ||
"line": 13, | ||
"column": 0, | ||
"character": 214 | ||
}, | ||
"end": { | ||
"line": 13, | ||
"column": 43, | ||
"character": 257 | ||
}, | ||
"pos": 214 | ||
}, | ||
{ | ||
"code": "a11y-click-events-have-key-events", | ||
"message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", | ||
"start": { | ||
"line": 15, | ||
"column": 0, | ||
"character": 259 | ||
}, | ||
"end": { | ||
"line": 15, | ||
"column": 27, | ||
"character": 286 | ||
}, | ||
"pos": 259 | ||
}, | ||
{ | ||
"code": "a11y-click-events-have-key-events", | ||
"message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", | ||
"start": { | ||
"line": 16, | ||
"column": 0, | ||
"character": 287 | ||
}, | ||
"end": { | ||
"line": 16, | ||
"column": 24, | ||
"character": 311 | ||
}, | ||
"pos": 287 | ||
}, | ||
{ | ||
"code": "a11y-click-events-have-key-events", | ||
"message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", | ||
"start": { | ||
"line": 17, | ||
"column": 0, | ||
"character": 312 | ||
}, | ||
"end": { | ||
"line": 17, | ||
"column": 27, | ||
"character": 339 | ||
}, | ||
"pos": 312 | ||
}, | ||
{ | ||
"code": "a11y-click-events-have-key-events", | ||
"message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", | ||
"start": { | ||
"line": 18, | ||
"column": 0, | ||
"character": 340 | ||
}, | ||
"end": { | ||
"line": 18, | ||
"column": 26, | ||
"character": 366 | ||
}, | ||
"pos": 340 | ||
}, | ||
{ | ||
"code": "a11y-click-events-have-key-events", | ||
"message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", | ||
"start": { | ||
"line": 19, | ||
"column": 0, | ||
"character": 367 | ||
}, | ||
"end": { | ||
"line": 19, | ||
"column": 26, | ||
"character": 393 | ||
}, | ||
"pos": 367 | ||
} | ||
] |