Skip to content

Commit

Permalink
Use handlers from recommended rule config
Browse files Browse the repository at this point in the history
  • Loading branch information
timmcca-be committed Apr 13, 2023
1 parent 0a4e452 commit 95246d9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 50 deletions.
6 changes: 4 additions & 2 deletions src/compiler/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Literal } from 'estree';
import compiler_warnings from '../compiler_warnings';
import compiler_errors from '../compiler_errors';
import { ARIARoleDefinitionKey, roles, aria, ARIAPropertyDefinition, ARIAProperty } from 'aria-query';
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_static_element, has_disabled_attribute, is_interactive_handler } from '../utils/a11y';
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_static_element, has_disabled_attribute } from '../utils/a11y';

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(' ');
const aria_attribute_set = new Set(aria_attributes);
Expand Down Expand Up @@ -777,7 +777,9 @@ export default class Element extends Node {
!is_non_interactive_roles(role) &&
!is_abstract_role(role)
) {
const interactive_handlers = handlers.map((handler) => handler.name).filter(is_interactive_handler);
const interactive_handlers = handlers
.map((handler) => handler.name)
.filter((handlerName) => a11y_interactive_handlers.has(handlerName));
if (interactive_handlers.length > 0) {
component.warn(
this,
Expand Down
38 changes: 0 additions & 38 deletions src/compiler/compile/utils/a11y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,41 +241,3 @@ export function is_semantic_role_element(
}
return false;
}

const interactive_handlers = new Set([
// Focus
'focus',
'focusin',
'focusout',
'blur',

// Keyboard
'keydown',
'keypress',
'keyup',

// Mouse
'auxclick',
'click',
'contextmenu',
'dblclick',
'drag',
'dragend',
'dragenter',
'dragexit',
'dragleave',
'dragover',
'dragstart',
'drop',
'mousedown',
'mouseenter',
'mouseleave',
'mousemove',
'mouseout',
'mouseover',
'mouseup'
]);

export function is_interactive_handler(handler: string) {
return interactive_handlers.has(handler);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<div on:copy={() => {}} />
<a href="/foo" on:click={() => {}}>link</a>
<div role={dynamicRole} on:click={() => {}} />
<footer on:keydown={() => {}} />

<!-- invalid -->
<div on:keydown={() => {}} />
<!-- svelte-ignore a11y-missing-attribute -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
{
"code": "a11y-no-static-element-interactions",
"end": {
"character": 347,
"character": 381,
"column": 29,
"line": 13
"line": 15
},
"message": "A11y: <div> with keydown handler must have an ARIA role",
"pos": 318,
"pos": 352,
"start": {
"character": 318,
"character": 352,
"column": 0,
"line": 13
"line": 15
}
},
{
"code": "a11y-no-static-element-interactions",
"end": {
"character": 470,
"character": 504,
"column": 76,
"line": 15
"line": 17
},
"message": "A11y: <a> with mousedown, mouseup handlers must have an ARIA role",
"pos": 394,
"pos": 428,
"start": {
"character": 394,
"character": 428,
"column": 0,
"line": 15
"line": 17
}
}
]

0 comments on commit 95246d9

Please sign in to comment.