Skip to content

Commit f5a4e2d

Browse files
committed
Corrected AccName algorithm to parse name and description tracks separatly to prevent accedental suppressing when overlapping during recursion.
1 parent c67d0e2 commit f5a4e2d

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

docs/Sample JavaScript Recursion Algorithm/recursion.js

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Distributed under the terms of the Open Source Initiative OSI - MIT License
1414
window[nameSpace] = {};
1515
nameSpace = window[nameSpace];
1616
}
17-
nameSpace.getAccNameVersion = "2.57";
17+
nameSpace.getAccNameVersion = "2.58";
1818
// AccName Computation Prototype
1919
nameSpace.getAccName = nameSpace.calcNames = function(
2020
node,
@@ -34,7 +34,11 @@ Distributed under the terms of the Open Source Initiative OSI - MIT License
3434
var rootNode = node;
3535
var rootRole = trim(node.getAttribute("role") || "");
3636
// Track nodes to prevent duplicate node reference parsing.
37-
var nodes = [];
37+
// Separating Name and Description to prevent duplicate node references from suppressing one or the other from being fully computed.
38+
var nodes = {
39+
name: [],
40+
desc: []
41+
};
3842
// Track aria-owns references to prevent duplicate parsing.
3943
var owns = [];
4044

@@ -147,7 +151,12 @@ Plus roles extended for the Role Parity project.
147151
after: ""
148152
};
149153

150-
if (!skipTo.tag && !skipTo.role && nodes.indexOf(refNode) === -1) {
154+
if (
155+
!skipTo.tag &&
156+
!skipTo.role &&
157+
nodes[!ownedBy.computingDesc ? "name" : "desc"].indexOf(refNode) ===
158+
-1
159+
) {
151160
// Store the before and after pseudo element 'content' values for the top level DOM node
152161
// Note: If the pseudo element includes block level styling, a space will be added, otherwise inline is asumed and no spacing is added.
153162
cssOP = getCSSText(refNode, null);
@@ -273,8 +282,13 @@ Plus roles extended for the Role Parity project.
273282
return result;
274283
}
275284

276-
if (!skipTo.tag && !skipTo.role && nodes.indexOf(node) === -1) {
277-
nodes.push(node);
285+
if (
286+
!skipTo.tag &&
287+
!skipTo.role &&
288+
nodes[!ownedBy.computingDesc ? "name" : "desc"].indexOf(node) ===
289+
-1
290+
) {
291+
nodes[!ownedBy.computingDesc ? "name" : "desc"].push(node);
278292
} else {
279293
// Abort if this node has already been processed.
280294
return result;
@@ -291,8 +305,14 @@ Plus roles extended for the Role Parity project.
291305
};
292306

293307
var parent = refNode === node ? node : node.parentNode;
294-
if (!skipTo.tag && !skipTo.role && nodes.indexOf(parent) === -1) {
295-
nodes.push(parent);
308+
if (
309+
!skipTo.tag &&
310+
!skipTo.role &&
311+
nodes[!ownedBy.computingDesc ? "name" : "desc"].indexOf(
312+
parent
313+
) === -1
314+
) {
315+
nodes[!ownedBy.computingDesc ? "name" : "desc"].push(parent);
296316
// Store the before and after pseudo element 'content' values for the current node container element
297317
// Note: If the pseudo element includes block level styling, a space will be added, otherwise inline is asumed and no spacing is added.
298318
cssO = getCSSText(parent, refNode);
@@ -416,7 +436,8 @@ Plus roles extended for the Role Parity project.
416436
parts.push(
417437
walk(element, true, false, [node], false, {
418438
ref: ownedBy,
419-
top: element
439+
top: element,
440+
computingDesc: true
420441
}).name
421442
);
422443
}
@@ -1527,18 +1548,21 @@ Plus roles extended for the Role Parity project.
15271548
var accName = trim(accProps.name.replace(/\s+/g, " "));
15281549
var accDesc = trim(accProps.title.replace(/\s+/g, " "));
15291550

1530-
if (accName === accDesc) {
1531-
// If both Name and Description properties match, then clear the Description property value.
1532-
accDesc = "";
1533-
}
1551+
// if (accName === accDesc) {
1552+
// If both Name and Description properties match, then clear the Description property value. (Ideal but not in the spec so commented out.)
1553+
// accDesc = "";
1554+
// }
15341555

15351556
props.hasUpperCase =
15361557
rootRole && rootRole !== rootRole.toLowerCase() ? true : false;
15371558
props.name = accName;
15381559
props.desc = accDesc;
15391560

15401561
// Clear track variables
1541-
nodes = [];
1562+
nodes = {
1563+
name: [],
1564+
desc: []
1565+
};
15421566
owns = [];
15431567
} catch (e) {
15441568
props.error = e;

0 commit comments

Comments
 (0)