mirror of https://github.com/sveltejs/svelte
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>pull/7838/head
parent
64690974dd
commit
82013aa161
@ -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} />
|
@ -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
|
||||
}
|
||||
]
|
Loading…
Reference in new issue