forked from vue-a11y/eslint-plugin-vuejs-accessibility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-static-element-interactions.ts
54 lines (46 loc) · 1.24 KB
/
no-static-element-interactions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Rule } from "eslint";
import {
defineTemplateBodyVisitor,
getElementAttributeValue,
hasOnDirectives,
interactiveHandlers,
isHiddenFromScreenReader,
isInteractiveElement,
isInteractiveRole,
isPresentationRole, makeDocsURL
} from "../utils";
import { dom } from "aria-query";
const rule: Rule.RuleModule = {
meta: {
type: "problem",
docs: {
url: makeDocsURL("no-static-element-interactions")
},
messages: {
default: "Visible, non-interactive elements should not have an interactive handler."
},
schema: []
},
create (context: Rule.RuleContext): Rule.RuleListener {
return defineTemplateBodyVisitor(context, {
VElement (node) {
const role = getElementAttributeValue(node, "role");
const domElements = [...dom.keys()];
if(!domElements.includes(node.name)) {
return;
}
if(isHiddenFromScreenReader(node) || isPresentationRole(node)) {
return;
}
if(
hasOnDirectives(node, interactiveHandlers) &&
!isInteractiveElement(node) &&
!isInteractiveRole(role)
) {
context.report({ node: node as any, messageId: "default" });
}
}
});
},
};
export default rule;