Skip to content

Commit ce27e34

Browse files
committed
Corrected a bug when referencing the same id when using both aria-labelleddby and aria-describedby on the same root node.
1 parent f1e1ce3 commit ce27e34

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

docs/Sample JavaScript Recursion Algorithm/recursion.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*!
1+
/*@license
22
CalcNames: The AccName Computation Prototype, compute the Name and Description property values for a DOM node
33
Returns an object with 'name' and 'desc' properties.
44
Functionality mirrors the steps within the W3C Accessible Name and Description computation algorithm.
@@ -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.55";
17+
nameSpace.getAccNameVersion = "2.56";
1818
// AccName Computation Prototype
1919
nameSpace.getAccName = nameSpace.calcNames = function(
2020
node,
@@ -372,6 +372,32 @@ Plus roles extended for the Role Parity project.
372372
ownedBy[node.id].target === node))
373373
);
374374

375+
// Check for non-empty value of aria-labelledby on current node, follow each ID ref, then stop and process no deeper.
376+
if (!stop && !skipTo.tag && !skipTo.role && aLabelledby) {
377+
ids = aLabelledby.split(/\s+/);
378+
parts = [];
379+
for (i = 0; i < ids.length; i++) {
380+
element = docO.getElementById(ids[i]);
381+
// Also prevent the current form field from having its value included in the naming computation if nested as a child of label
382+
parts.push(
383+
walk(element, true, skip, [node], element === refNode, {
384+
ref: ownedBy,
385+
top: element
386+
}).name
387+
);
388+
}
389+
// Check for blank value, since whitespace chars alone are not valid as a name
390+
name = trim(parts.join(" "));
391+
392+
if (trim(name)) {
393+
hasName = true;
394+
hLabel = true;
395+
hasLabel = true;
396+
// Abort further recursion if name is valid.
397+
result.skip = true;
398+
}
399+
}
400+
375401
// Check for non-empty value of aria-describedby/description if current node equals reference node, follow each ID ref, then stop and process no deeper.
376402
if (
377403
!stop &&
@@ -405,32 +431,6 @@ Plus roles extended for the Role Parity project.
405431
}
406432
}
407433

408-
// Check for non-empty value of aria-labelledby on current node, follow each ID ref, then stop and process no deeper.
409-
if (!stop && !skipTo.tag && !skipTo.role && aLabelledby) {
410-
ids = aLabelledby.split(/\s+/);
411-
parts = [];
412-
for (i = 0; i < ids.length; i++) {
413-
element = docO.getElementById(ids[i]);
414-
// Also prevent the current form field from having its value included in the naming computation if nested as a child of label
415-
parts.push(
416-
walk(element, true, skip, [node], element === refNode, {
417-
ref: ownedBy,
418-
top: element
419-
}).name
420-
);
421-
}
422-
// Check for blank value, since whitespace chars alone are not valid as a name
423-
name = trim(parts.join(" "));
424-
425-
if (trim(name)) {
426-
hasName = true;
427-
hLabel = true;
428-
hasLabel = true;
429-
// Abort further recursion if name is valid.
430-
result.skip = true;
431-
}
432-
}
433-
434434
// Otherwise, if current node has a non-empty aria-label then set as name and process no deeper within the branch.
435435
if (
436436
!skipTo.tag &&

0 commit comments

Comments
 (0)