diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index d4a3b85e6c..3e6d886a5d 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -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 } from '../utils/a11y'; +import { is_interactive_element, is_non_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); diff --git a/src/compiler/compile/utils/a11y.ts b/src/compiler/compile/utils/a11y.ts index 0936988072..bc23f5c818 100644 --- a/src/compiler/compile/utils/a11y.ts +++ b/src/compiler/compile/utils/a11y.ts @@ -57,10 +57,7 @@ export function is_presentation_role(role: ARIARoleDefinitionKey) { return presentation_roles.has(role); } -export function is_hidden_from_screen_reader( - tag_name: string, - attribute_map: Map -) { +export function is_hidden_from_screen_reader(tag_name: string, attribute_map: Map) { if (tag_name === 'input') { const type = attribute_map.get('type')?.get_static_value(); @@ -212,21 +209,11 @@ export function is_static_element(tag_name: string, attribute_map: Map -) { +export function is_semantic_role_element(role: ARIARoleDefinitionKey, tag_name: string, attribute_map: Map) { for (const [schema, ax_object] of elementAXObjects.entries()) { - if ( - schema.name === tag_name && - (!schema.attributes || - schema.attributes.every( - (attr) => - attribute_map.has(attr.name) && - attribute_map.get(attr.name).get_static_value() === attr.value - )) - ) { + if (schema.name === tag_name && (!schema.attributes || schema.attributes.every( + (attr) => attribute_map.has(attr.name) && attribute_map.get(attr.name).get_static_value() === attr.value + ))) { for (const name of ax_object) { const roles = AXObjectRoles.get(name); if (roles) { diff --git a/test/validator/samples/a11y-click-events-have-key-events/input.svelte b/test/validator/samples/a11y-click-events-have-key-events/input.svelte index 428114c920..c6ac9ac866 100644 --- a/test/validator/samples/a11y-click-events-have-key-events/input.svelte +++ b/test/validator/samples/a11y-click-events-have-key-events/input.svelte @@ -64,4 +64,5 @@
+ diff --git a/test/validator/samples/a11y-click-events-have-key-events/warnings.json b/test/validator/samples/a11y-click-events-have-key-events/warnings.json index 554d95244b..42eaed0025 100644 --- a/test/validator/samples/a11y-click-events-have-key-events/warnings.json +++ b/test/validator/samples/a11y-click-events-have-key-events/warnings.json @@ -3,86 +3,47 @@ "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": { -<<<<<<< HEAD - "line": 12, + "line": 13, "column": 0 }, "end": { - "line": 12, + "line": 13, "column": 23 } -======= - "line": 13, - "column": 0, - "character": 249 - }, - "end": { - "line": 13, - "column": 23, - "character": 272 - }, - "pos": 249 ->>>>>>> 752aa35ed (add no-static-element-interactions compiler rule) }, { "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": { -<<<<<<< HEAD - "line": 13, + "line": 15, "column": 0 }, "end": { - "line": 13, + "line": 15, "column": 43 } -======= - "line": 15, - "column": 0, - "character": 332 - }, - "end": { - "line": 15, - "column": 43, - "character": 375 - }, - "pos": 332 ->>>>>>> 752aa35ed (add no-static-element-interactions compiler rule) }, { "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": { -<<<<<<< HEAD - "line": 15, + "line": 18, "column": 0 }, "end": { - "line": 15, + "line": 18, "column": 27 } -======= - "line": 18, - "column": 0, - "character": 436 - }, - "end": { - "line": 18, - "column": 27, - "character": 463 - }, - "pos": 436 ->>>>>>> 752aa35ed (add no-static-element-interactions compiler rule) }, { "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, + "line": 19, "column": 0 }, "end": { - "line": 16, + "line": 19, "column": 24 } }, @@ -90,11 +51,11 @@ "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, + "line": 20, "column": 0 }, "end": { - "line": 17, + "line": 20, "column": 27 } }, @@ -102,50 +63,24 @@ "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": { -<<<<<<< HEAD - "line": 18, + "line": 22, "column": 0 }, "end": { - "line": 18, + "line": 22, "column": 26 } -======= - "line": 22, - "column": 0, - "character": 576 - }, - "end": { - "line": 22, - "column": 26, - "character": 602 - }, - "pos": 576 ->>>>>>> 752aa35ed (add no-static-element-interactions compiler rule) }, { "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": { -<<<<<<< HEAD - "line": 19, + "line": 23, "column": 0 }, "end": { - "line": 19, + "line": 23, "column": 26 } -======= - "line": 23, - "column": 0, - "character": 603 - }, - "end": { - "line": 23, - "column": 26, - "character": 629 - }, - "pos": 603 ->>>>>>> 752aa35ed (add no-static-element-interactions compiler rule) } ] diff --git a/test/validator/samples/a11y-mouse-events-have-key-events/warnings.json b/test/validator/samples/a11y-mouse-events-have-key-events/warnings.json index 87d2768178..7aae042a79 100644 --- a/test/validator/samples/a11y-mouse-events-have-key-events/warnings.json +++ b/test/validator/samples/a11y-mouse-events-have-key-events/warnings.json @@ -1,50 +1,50 @@ [ - { - "code": "a11y-mouse-events-have-key-events", - "end": { - "column": 35, - "line": 10 - }, - "message": "A11y: on:mouseover must be accompanied by on:focus", - "start": { - "column": 0, - "line": 10 - } - }, - { - "code": "a11y-mouse-events-have-key-events", - "end": { - "column": 51, - "line": 12 - }, - "message": "A11y: on:mouseover must be accompanied by on:focus", - "start": { - "column": 0, - "line": 12 - } - }, - { - "code": "a11y-mouse-events-have-key-events", - "end": { - "column": 34, - "line": 13 - }, - "message": "A11y: on:mouseout must be accompanied by on:blur", - "start": { - "column": 0, - "line": 13 - } - }, - { - "code": "a11y-mouse-events-have-key-events", - "end": { - "column": 50, - "line": 15 - }, - "message": "A11y: on:mouseout must be accompanied by on:blur", - "start": { - "column": 0, - "line": 15 - } - } + { + "code": "a11y-mouse-events-have-key-events", + "end": { + "column": 35, + "line": 11 + }, + "message": "A11y: on:mouseover must be accompanied by on:focus", + "start": { + "column": 0, + "line": 11 + } + }, + { + "code": "a11y-mouse-events-have-key-events", + "end": { + "column": 51, + "line": 15 + }, + "message": "A11y: on:mouseover must be accompanied by on:focus", + "start": { + "column": 0, + "line": 15 + } + }, + { + "code": "a11y-mouse-events-have-key-events", + "end": { + "column": 34, + "line": 17 + }, + "message": "A11y: on:mouseout must be accompanied by on:blur", + "start": { + "column": 0, + "line": 17 + } + }, + { + "code": "a11y-mouse-events-have-key-events", + "end": { + "column": 50, + "line": 21 + }, + "message": "A11y: on:mouseout must be accompanied by on:blur", + "start": { + "column": 0, + "line": 21 + } + } ] diff --git a/test/validator/samples/a11y-no-static-element-interactions/input.svelte b/test/validator/samples/a11y-no-static-element-interactions/input.svelte index b5281645fb..06a389d025 100644 --- a/test/validator/samples/a11y-no-static-element-interactions/input.svelte +++ b/test/validator/samples/a11y-no-static-element-interactions/input.svelte @@ -4,6 +4,7 @@