Skip to content

Commit 1ff5f64

Browse files
committed
Changed wrapping input label to detect any parent <label> rather than just a direct parent. This is not detecting for a valid phrasing content node (i.e. a div is not a valid child of a label), which is not in the scope of wcag testing. This resolves #209.
1 parent 64be9c8 commit 1ff5f64

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

HTMLCS.Util.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,39 @@ _global.HTMLCS.util = function() {
814814
};
815815

816816

817+
/**
818+
* Iterate parent nodes of an element.
819+
*
820+
* @param {DOMNode} node Node to search from.
821+
* @param {Function} cb Callback function providing each parent node.
822+
*
823+
* @return void
824+
*/
825+
self.eachParentNode = function(node, cb) {
826+
while (node && node.parentNode) {
827+
cb(node);
828+
node = node.parentNode;
829+
};
830+
};
831+
832+
833+
/**
834+
* Returns TRUE if the provided node name is not a valid phrasing node.
835+
*
836+
* @param {String} nodeName The node name to test.
837+
*
838+
* @return {Boolean}
839+
*/
840+
self.isPhrasingNode = function(nodeName) {
841+
var nodeNames = [ 'abbr', 'audio', 'b', 'bdo', 'br', 'button', 'canvas', 'cite', 'code', 'command', 'data',
842+
'datalist', 'dfn', 'em', 'embed', 'i', 'iframe', 'img', 'input', 'kbd', 'keygen', 'label', 'mark', 'math',
843+
'meter', 'noscript', 'object', 'output', 'progress', 'q', 'ruby', 'samp', 'script', 'select', 'small',
844+
'span', 'strong', 'sub', 'sup', 'svg', 'textarea', 'time', 'var', 'video', 'wbr'];
845+
846+
return nodeNames.indexOf(nodeName.toLowerCase()) !== -1;
847+
};
848+
849+
817850
self.getChildrenForTable = function(table, childNodeName)
818851
{
819852
if (table.nodeName.toLowerCase() !== 'table') {

Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,15 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = {
238238
}
239239

240240
// Find an implicit label.
241-
var implicitLabel = element.parentNode;
242-
if (implicitLabel && (implicitLabel.nodeName.toLowerCase() === 'label')) {
241+
var foundImplicit = false;
242+
if (element.parentNode) {
243+
HTMLCS.util.eachParentNode(element, function(parent) {
244+
if (parent.nodeName.toLowerCase() === 'label') {
245+
foundImplicit = true;
246+
}
247+
});
248+
}
249+
if (foundImplicit === true) {
243250
addToLabelList('implicit');
244251
}
245252

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>412_wrapping_label</title>
5+
<!-- @HTMLCS_Test@
6+
Name: SC 4.1.2 testing of wrapping labels
7+
Standard: WCAG2AAA
8+
Assert: No Warning *.H91.InputRadio.Name on #test1
9+
Assert: No Error *.H91.InputRadio.Name on #test1
10+
Assert: Error *.H91.InputRadio.Name on #test2
11+
-->
12+
</head>
13+
<body>
14+
<form>
15+
<div>
16+
<label>
17+
<span>
18+
<input type="radio" name="foo" value="foo" id="test1" />
19+
</span>
20+
<span>
21+
Lorem ipsum
22+
</span>
23+
</label>
24+
</div>
25+
<div>
26+
<span>
27+
<input type="radio" name="foo" value="foo" id="test2" />
28+
</span>
29+
<span>
30+
Lorem ipsum
31+
</span>
32+
</div>
33+
</form>
34+
</body>
35+
</html>

0 commit comments

Comments
 (0)