-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathhasAccessibleChild.ts
35 lines (31 loc) · 995 Bytes
/
hasAccessibleChild.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
import type { AST } from "vue-eslint-parser";
import getElementType from "./getElementType";
import isHiddenFromScreenReader from "./isHiddenFromScreenReader";
function hasAccessibleChild(
node: AST.VElement,
accessibleChildTypes: string[] = []
): boolean {
return node.children.some((child) => {
switch (child.type) {
case "VText":
return child.value.trim().length > 0;
case "VElement": {
const elementType = getElementType(child);
return (
accessibleChildTypes.includes(elementType) ||
child.rawName === "slot" ||
(!isHiddenFromScreenReader(child) &&
hasAccessibleChild(child, accessibleChildTypes))
);
}
case "VExpressionContainer":
if (child.expression && child.expression.type === "Identifier") {
return child.expression.name !== "undefined";
}
return true;
default:
return false;
}
});
}
export default hasAccessibleChild;