@@ -4,7 +4,7 @@ import { getNodeAccessibilityData } from "./getNodeAccessibilityData/index";
44import { getNodeByIdRef } from "./getNodeByIdRef" ;
55import { isDialogRole } from "./isDialogRole" ;
66import { isElement } from "./isElement" ;
7- import { isInaccessible } from "dom-accessibility-api " ;
7+ import { isHiddenFromAccessibilityTree } from "./isHiddenFromAccessibilityTree " ;
88
99export interface AccessibilityNode {
1010 accessibleAttributeLabels : string [ ] ;
@@ -15,6 +15,7 @@ export interface AccessibilityNode {
1515 allowedAccessibilityChildRoles : string [ ] [ ] ;
1616 alternateReadingOrderParents : Node [ ] ;
1717 childrenPresentational : boolean ;
18+ isInert : boolean ;
1819 node : Node ;
1920 parentAccessibilityNodeTree : AccessibilityNodeTree | null ;
2021 parent : Node | null ;
@@ -125,33 +126,6 @@ function getOwnedNodes(node: Node, container: Node) {
125126 return ownedNodes ;
126127}
127128
128- const TEXT_NODE = 3 ;
129-
130- function isHiddenFromAccessibilityTree ( node : Node | null ) : node is null {
131- if ( ! node ) {
132- return true ;
133- }
134-
135- // `node.textContent` is only `null` for `document` and `doctype`.
136-
137- if ( node . nodeType === TEXT_NODE && node . textContent ! . trim ( ) ) {
138- return false ;
139- }
140-
141- if ( ! isElement ( node ) ) {
142- return true ;
143- }
144-
145- try {
146- return isInaccessible ( node ) ;
147- } catch {
148- // Some elements aren't supported by DOM implementations such as JSDOM.
149- // E.g. `<math>`, see https://github.com/jsdom/jsdom/issues/3515
150- // We ignore these nodes at the moment as we can't support them.
151- return true ;
152- }
153- }
154-
155129function growTree (
156130 node : Node ,
157131 tree : Omit <
@@ -198,7 +172,7 @@ function growTree(
198172
199173 const alternateReadingOrderParents = alternateReadingOrderMap . has ( childNode )
200174 ? // `alternateReadingOrderMap.has(childNode)` null guards here.
201-
175+
202176 Array . from ( alternateReadingOrderMap . get ( childNode ) ! )
203177 : [ ] ;
204178
@@ -209,14 +183,14 @@ function growTree(
209183 allowedAccessibilityChildRoles,
210184 childrenPresentational,
211185 isExplicitPresentational,
186+ isInert,
212187 role,
213188 spokenRole,
214189 } = getNodeAccessibilityData ( {
215190 allowedAccessibilityRoles : tree . allowedAccessibilityChildRoles ,
216- alternateReadingOrderParents,
217- container,
218- node : childNode ,
191+ inheritedImplicitInert : tree . isInert ,
219192 inheritedImplicitPresentational : tree . childrenPresentational ,
193+ node : childNode ,
220194 } ) ;
221195
222196 const childTree = growTree (
@@ -229,6 +203,7 @@ function growTree(
229203 alternateReadingOrderParents,
230204 children : [ ] ,
231205 childrenPresentational,
206+ isInert,
232207 node : childNode ,
233208 parentAccessibilityNodeTree : null , // Added during flattening
234209 parent : node ,
@@ -266,7 +241,7 @@ function growTree(
266241
267242 const alternateReadingOrderParents = alternateReadingOrderMap . has ( childNode )
268243 ? // `alternateReadingOrderMap.has(childNode)` null guards here.
269-
244+
270245 Array . from ( alternateReadingOrderMap . get ( childNode ) ! )
271246 : [ ] ;
272247
@@ -276,15 +251,15 @@ function growTree(
276251 accessibleValue,
277252 allowedAccessibilityChildRoles,
278253 childrenPresentational,
254+ isInert,
279255 isExplicitPresentational,
280256 role,
281257 spokenRole,
282258 } = getNodeAccessibilityData ( {
283259 allowedAccessibilityRoles : tree . allowedAccessibilityChildRoles ,
284- alternateReadingOrderParents,
285- container,
286- node : childNode ,
260+ inheritedImplicitInert : tree . isInert ,
287261 inheritedImplicitPresentational : tree . childrenPresentational ,
262+ node : childNode ,
288263 } ) ;
289264
290265 const childTree = growTree (
@@ -297,6 +272,7 @@ function growTree(
297272 alternateReadingOrderParents,
298273 children : [ ] ,
299274 childrenPresentational,
275+ isInert,
300276 node : childNode ,
301277 parentAccessibilityNodeTree : null , // Added during flattening
302278 parent : node ,
@@ -334,14 +310,14 @@ export function createAccessibilityTree(
334310 accessibleValue,
335311 allowedAccessibilityChildRoles,
336312 childrenPresentational,
313+ isInert,
337314 role,
338315 spokenRole,
339316 } = getNodeAccessibilityData ( {
340317 allowedAccessibilityRoles : [ ] ,
341- alternateReadingOrderParents : [ ] ,
342- container : node ,
343318 node,
344319 inheritedImplicitPresentational : false ,
320+ inheritedImplicitInert : false ,
345321 } ) ;
346322
347323 const tree = growTree (
@@ -354,6 +330,7 @@ export function createAccessibilityTree(
354330 alternateReadingOrderParents : [ ] ,
355331 children : [ ] ,
356332 childrenPresentational,
333+ isInert,
357334 node,
358335 parentAccessibilityNodeTree : null ,
359336 parent : null ,
0 commit comments