Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(label-title-only): allow hidden labels (#3183)
  • Loading branch information
macjohnny authored and straker committed Oct 18, 2021
1 parent 66db765 commit ab636ef
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 37 deletions.
64 changes: 32 additions & 32 deletions doc/rule-descriptions.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/commons/aria/arialabelledby-text.js
Expand Up @@ -13,7 +13,7 @@ import { getNodeFromTree } from '../../core/utils';
* @property {Bool} inControlContext Whether or not the lookup is part of a native label reference
* @property {Element} startNode First node in accessible name computation
* @property {Bool} debug Enable logging for formControlValue
* @return {string} Cancatinated text value for referenced elements
* @return {string} Concatenated text value for referenced elements
*/
function arialabelledbyText(vNode, context = {}) {
if (!(vNode instanceof AbstractVirtualNode)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/aria/label-virtual.js
Expand Up @@ -21,7 +21,7 @@ function labelVirtual(virtualNode) {
candidate = ref
.map(thing => {
const vNode = getNodeFromTree(thing);
return vNode ? visibleVirtual(vNode, true) : '';
return vNode ? visibleVirtual(vNode) : '';
})
.join(' ')
.trim();
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/label-title-only.json
Expand Up @@ -4,7 +4,7 @@
"matches": "label-matches",
"tags": ["cat.forms", "best-practice"],
"metadata": {
"description": "Ensures that every form element is not solely labeled using the title or aria-describedby attributes",
"description": "Ensures that every form element has a visible label and is not solely labeled using hidden labels, or the title or aria-describedby attributes",
"help": "Form elements should have a visible label"
},
"all": [],
Expand Down
11 changes: 11 additions & 0 deletions test/integration/rules/label-title-only/label-title-only.html
Expand Up @@ -27,4 +27,15 @@

<input type="text" id="pass7" aria-describedby="hi" aria-label="Hi" />
<input id="pass8" aria-describedby="hi" aria-labelledby="hi" />

<div id="hihidden" aria-hidden="true">Hi hidden</div>
<input type="text" id="pass9" aria-labelledby="hihidden" />
<input type="text" id="pass10" title="Hello" aria-labelledby="hihidden" />
<input
type="text"
id="pass11"
title="Hello"
aria-describedby="hi"
aria-labelledby="hihidden"
/>
</form>
Expand Up @@ -10,6 +10,9 @@
["#pass5"],
["#pass6"],
["#pass7"],
["#pass8"]
["#pass8"],
["#pass9"],
["#pass10"],
["#pass11"]
]
}
3 changes: 3 additions & 0 deletions test/integration/rules/label/label.html
Expand Up @@ -60,4 +60,7 @@

<input id="pass16" role="none" disabled />
<input id="pass17" role="presentation" disabled />

<div id="hiddenlabel" aria-hidden="true">Hidden label</div>
<input type="text" id="pass18" aria-labelledby="hiddenlabel" />
</form>
3 changes: 2 additions & 1 deletion test/integration/rules/label/label.json
Expand Up @@ -26,6 +26,7 @@
["#pass15"],
["#pass16"],
["#pass17"],
["#pass-gh1176"]
["#pass-gh1176"],
["#pass18"]
]
}

0 comments on commit ab636ef

Please sign in to comment.