Skip to content

Commit dd3d9f6

Browse files
committed
Use handlers from recommended rule config
1 parent 4fe0ca2 commit dd3d9f6

File tree

4 files changed

+26
-50
lines changed

4 files changed

+26
-50
lines changed

src/compiler/compile/nodes/Element.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { Literal } from 'estree';
2424
import compiler_warnings from '../compiler_warnings';
2525
import compiler_errors from '../compiler_errors';
2626
import { ARIARoleDefintionKey, roles, aria, ARIAPropertyDefinition, ARIAProperty } from 'aria-query';
27-
import { is_non_interactive_element, is_interactive_element, is_non_interactive_roles, is_presentation_role, is_interactive_roles, is_hidden_from_screen_reader, is_semantic_role_element, is_abstract_role, is_interactive_handler } from '../utils/a11y';
27+
import { is_non_interactive_element, is_interactive_element, is_non_interactive_roles, is_presentation_role, is_interactive_roles, is_hidden_from_screen_reader, is_semantic_role_element, is_abstract_role } from '../utils/a11y';
2828

2929
const aria_attributes = 'activedescendant atomic autocomplete busy checked colcount colindex colspan controls current describedby description details disabled dropeffect errormessage expanded flowto grabbed haspopup hidden invalid keyshortcuts label labelledby level live modal multiline multiselectable orientation owns placeholder posinset pressed readonly relevant required roledescription rowcount rowindex rowspan selected setsize sort valuemax valuemin valuenow valuetext'.split(' ');
3030
const aria_attribute_set = new Set(aria_attributes);
@@ -75,6 +75,16 @@ const a11y_labelable = new Set([
7575
'textarea'
7676
]);
7777

78+
const a11y_interactive_handlers = new Set([
79+
'click',
80+
'mousedown',
81+
'mouseup',
82+
'keypress',
83+
'keydown',
84+
'keyup'
85+
]);
86+
87+
7888
const a11y_nested_implicit_semantics = new Map([
7989
['header', 'banner'],
8090
['footer', 'contentinfo']
@@ -615,7 +625,9 @@ export default class Element extends Node {
615625
!is_non_interactive_roles(role) &&
616626
!is_abstract_role(role)
617627
) {
618-
const interactive_handlers = handlers.map((handler) => handler.name).filter(is_interactive_handler);
628+
const interactive_handlers = handlers
629+
.map((handler) => handler.name)
630+
.filter((handlerName) => a11y_interactive_handlers.has(handlerName));
619631
if (interactive_handlers.length > 0) {
620632
component.warn(
621633
this,

src/compiler/compile/utils/a11y.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -240,41 +240,3 @@ export function is_semantic_role_element(
240240
}
241241
return false;
242242
}
243-
244-
const interactive_handlers = new Set([
245-
// Focus
246-
'focus',
247-
'focusin',
248-
'focusout',
249-
'blur',
250-
251-
// Keyboard
252-
'keydown',
253-
'keypress',
254-
'keyup',
255-
256-
// Mouse
257-
'auxclick',
258-
'click',
259-
'contextmenu',
260-
'dblclick',
261-
'drag',
262-
'dragend',
263-
'dragenter',
264-
'dragexit',
265-
'dragleave',
266-
'dragover',
267-
'dragstart',
268-
'drop',
269-
'mousedown',
270-
'mouseenter',
271-
'mouseleave',
272-
'mousemove',
273-
'mouseout',
274-
'mouseover',
275-
'mouseup'
276-
]);
277-
278-
export function is_interactive_handler(handler: string) {
279-
return interactive_handlers.has(handler);
280-
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<div on:copy={() => {}} />
1010
<a href="/foo" on:click={() => {}}>link</a>
1111
<div role={dynamicRole} on:click={() => {}} />
12+
<footer on:keydown={() => {}} />
13+
1214
<!-- invalid -->
1315
<div on:keydown={() => {}} />
1416
<!-- 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": 347,
5+
"character": 381,
66
"column": 29,
7-
"line": 13
7+
"line": 15
88
},
99
"message": "A11y: <div> with keydown handler must have an ARIA role",
10-
"pos": 318,
10+
"pos": 352,
1111
"start": {
12-
"character": 318,
12+
"character": 352,
1313
"column": 0,
14-
"line": 13
14+
"line": 15
1515
}
1616
},
1717
{
1818
"code": "a11y-no-static-element-interactions",
1919
"end": {
20-
"character": 470,
20+
"character": 504,
2121
"column": 76,
22-
"line": 15
22+
"line": 17
2323
},
2424
"message": "A11y: <a> with mousedown, mouseup handlers must have an ARIA role",
25-
"pos": 394,
25+
"pos": 428,
2626
"start": {
27-
"character": 394,
27+
"character": 428,
2828
"column": 0,
29-
"line": 15
29+
"line": 17
3030
}
3131
}
3232
]

0 commit comments

Comments
 (0)