forked from angular-eslint/angular-eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
53 lines (49 loc) · 2.19 KB
/
index.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
import type { TmplAstElement } from '@angular-eslint/bundled-angular-compiler';
import type { ARIARole, ARIARoleRelationConcept } from 'aria-query';
import { attributesComparator } from '../attributes-comparator';
import { getAttributeValue } from '../get-attribute-value';
import { getDomElements } from '../get-dom-elements';
import { getInteractiveElementAXObjectSchemas } from './get-interactive-element-ax-object-schemas';
import { getInteractiveElementRoleSchemas } from './get-interactive-element-role-schemas';
import {
getNonInteractiveElementRoleSchemas,
getNonInteractiveRoles,
} from './get-non-interactive-element-role-schemas';
function checkIsInteractiveElement(node: TmplAstElement): boolean {
function elementSchemaMatcher({ attributes, name }: ARIARoleRelationConcept) {
return node.name === name && attributesComparator(attributes ?? [], node);
}
// Check in elementRoles for inherent interactive role associations for
// this element.
const isInherentInteractiveElement =
getInteractiveElementRoleSchemas().some(elementSchemaMatcher);
if (isInherentInteractiveElement) {
return true;
}
// Check in elementRoles for inherent non-interactive role associations for
// this element.
const isInherentNonInteractiveElement =
getNonInteractiveElementRoleSchemas().some(elementSchemaMatcher);
if (isInherentNonInteractiveElement) {
return false;
}
// Check in elementAXObjects for AX Tree associations for this element.
return getInteractiveElementAXObjectSchemas().some(elementSchemaMatcher);
}
function checkIsNonInteractiveRole(node: TmplAstElement): boolean {
return getNonInteractiveRoles().has(
getAttributeValue(node, 'role') as ARIARole,
);
}
/**
* Returns boolean indicating whether the given element is
* interactive on the DOM or not. Usually used when an element
* has a dynamic handler on it and we need to discern whether or not
* it's intention is to be interacted with on the DOM.
*/
export function isInteractiveElement(node: TmplAstElement): boolean {
return getDomElements().has(node.name) && checkIsInteractiveElement(node);
}
export function isNonInteractiveRole(node: TmplAstElement): boolean {
return checkIsNonInteractiveRole(node);
}