diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 002e09d9f9..ab5ddd2f07 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -424,6 +424,25 @@ export default class Element extends Node { }); } + if (name === "onmouseover") { + if (!this.attributes.find(i => i.name === 'onFocus')) { + component.warn(attribute, { + code: `a11y-mouse-events-have-key-events`, + message: `A11y: onMouseOver must be accompanied by onFocus for accessibility.` + }); + } + } + + if (name === "onmouseout") { + if (!this.attributes.find(i => i.name === 'onBlur')) { + component.warn(attribute, { + code: `a11y-mouse-events-have-key-events`, + message: `A11y: onMouseOut must be accompanied by onBlur for accessibility.` + }); + } + } + + attribute_map.set(attribute.name, attribute); }); } @@ -507,24 +526,6 @@ export default class Element extends Node { } } - if (attribute_map.has('onMouseOver') || attribute_map.has('onMouseOut')) { - if (attribute_map.has('onMouseOver') && !attribute_map.has('onFocus')) { - component.warn(this, { - code: `a11y-mouse-events-have-key-events`, - message: `A11y: onMouseOver must be accompanied by onFocus for accessibility.` - }); - } - - if (attribute_map.has('onMouseOut') && attribute_map.has('onBlur')) { - component.warn(this, { - code: `a11y-mouse-events-have-key-events`, - message: `A11y: onMouseOut must be accompanied by onBlur for accessibility.` - }); - } - - - } - if (a11y_no_onchange.has(this.name)) { if (handlers_map.has('change') && !handlers_map.has('blur')) { component.warn(this, { 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 bb956c2cd3..33617735c8 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 @@ -2,31 +2,31 @@ { "code": "a11y-mouse-events-have-key-events", "end": { - "character": 36, - "column": 36, + "character": 33, + "column": 33, "line": 1 }, "message": "A11y: onMouseOver must be accompanied by onFocus for accessibility.", - "pos": 0, + "pos": 5, "start": { - "character": 0, - "column": 0, + "character": 5, + "column": 5, "line": 1 } }, { "code": "a11y-mouse-events-have-key-events", "end": { - "character": 194, - "column": 59, - "line": 4 + "character": 69, + "column": 32, + "line": 2 }, "message": "A11y: onMouseOut must be accompanied by onBlur for accessibility.", - "pos": 135, + "pos": 42, "start": { - "character": 135, - "column": 0, - "line": 4 + "character": 42, + "column": 5, + "line": 2 } } ]