forked from vue-a11y/eslint-plugin-vuejs-accessibility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclick-events-have-key-events.ts
44 lines (41 loc) · 1.03 KB
/
click-events-have-key-events.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
import type { Rule } from "eslint";
import {
defineTemplateBodyVisitor,
hasOnDirective,
hasOnDirectives,
isCustomComponent,
isHiddenFromScreenReader,
isInteractiveElement,
isPresentationRole,
makeDocsURL
} from "../utils";
const rule: Rule.RuleModule = {
meta: {
type: "problem",
docs: {
url: makeDocsURL("click-events-have-key-events")
},
messages: {
default:
"Visible, non-interactive elements with click handlers must have at least one keyboard listener."
},
schema: []
},
create(context) {
return defineTemplateBodyVisitor(context, {
VElement(node) {
if (
!isCustomComponent(node) &&
hasOnDirective(node, "click") &&
!isHiddenFromScreenReader(node) &&
!isPresentationRole(node) &&
!isInteractiveElement(node) &&
!hasOnDirectives(node, ["keydown", "keyup", "keypress"])
) {
context.report({ node: node as any, messageId: "default" });
}
}
});
}
};
export default rule;