-
Notifications
You must be signed in to change notification settings - Fork 880
Expand file tree
/
Copy pathwidget-not-inline-matches.js
More file actions
39 lines (34 loc) · 1.18 KB
/
widget-not-inline-matches.js
File metadata and controls
39 lines (34 loc) · 1.18 KB
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
import { getRoleType } from '../commons/aria';
import { isFocusable, isInTabOrder, isInTextBlock } from '../commons/dom';
import svgNamespaceMatches from './svg-namespace-matches';
import { memoize } from '../core/utils';
export default function widgetNotInline(node, vNode) {
return matchesFns.every(fn => fn(node, vNode));
}
const matchesFns = [
(node, vNode) => isWidgetType(vNode),
(node, vNode) => isNotAreaElement(vNode),
(node, vNode) => !svgNamespaceMatches(node, vNode),
(node, vNode) => isFocusable(vNode),
// Skip nested widgets with tabindex=-1
(node, vNode) => isInTabOrder(vNode) || !hasWidgetAncestorInTabOrder(vNode),
node =>
!isInTextBlock(node, { noLengthCompare: true, includeInlineBlock: true })
];
function isWidgetType(vNode) {
return getRoleType(vNode) === 'widget';
}
function isNotAreaElement(vNode) {
return vNode.props.nodeName !== 'area';
}
const hasWidgetAncestorInTabOrder = memoize(
function hasWidgetAncestorInTabOrderMemoized(vNode) {
if (!vNode?.parent) {
return false;
}
if (isWidgetType(vNode.parent) && isInTabOrder(vNode.parent)) {
return true;
}
return hasWidgetAncestorInTabOrderMemoized(vNode.parent);
}
);