Skip to content

Commit 364eb72

Browse files
strakerWilcoFiers
andcommitted
fix(button-name,input-button-name,input-img-alt): allow label to give accessible name (#4607)
I'm not sure if this should close #4472 as that also deals with buttons with a different role running `button-name`. For sure this closes #3696 Closes: #3696 --------- Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>
1 parent a95ed13 commit 364eb72

17 files changed

Lines changed: 321 additions & 101 deletions

File tree

lib/checks/label/explicit.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"metadata": {
55
"impact": "critical",
66
"messages": {
7-
"pass": "Form element has an explicit <label>",
8-
"fail": "Form element does not have an explicit <label>",
7+
"pass": "Element has an explicit <label>",
8+
"fail": "Element does not have an explicit <label>",
99
"incomplete": "Unable to determine if form element has an explicit <label>"
1010
}
1111
}

lib/checks/label/implicit.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"metadata": {
55
"impact": "critical",
66
"messages": {
7-
"pass": "Form element has an implicit (wrapped) <label>",
8-
"fail": "Form element does not have an implicit (wrapped) <label>",
7+
"pass": "Element has an implicit (wrapped) <label>",
8+
"fail": "Element does not have an implicit (wrapped) <label>",
99
"incomplete": "Unable to determine if form element has an implicit (wrapped) <label>"
1010
}
1111
}

lib/commons/text/native-text-methods.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ const nativeTextMethods = {
1616
* @param {VirtualNode} element
1717
* @return {String} value text
1818
*/
19-
valueText: ({ actualNode }) => actualNode.value || '',
19+
valueText: vNode => vNode.props.value || '',
2020

2121
/**
2222
* Return default value of a button
2323
* @param {VirtualNode} element
2424
* @return {String} default button text
2525
*/
26-
buttonDefaultText: ({ actualNode }) =>
27-
defaultButtonValues[actualNode.type] || '',
26+
buttonDefaultText: vNode => defaultButtonValues[vNode.props.type] || '',
2827

2928
/**
3029
* Return caption text of an HTML table element

lib/rules/button-name.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"aria-label",
2727
"aria-labelledby",
2828
"non-empty-title",
29+
"implicit-label",
30+
"explicit-label",
2931
"presentational-role"
3032
],
3133
"none": []

lib/rules/input-button-name.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"aria-label",
2828
"aria-labelledby",
2929
"non-empty-title",
30+
"implicit-label",
31+
"explicit-label",
3032
"presentational-role"
3133
],
3234
"none": []

lib/rules/input-image-alt.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
"help": "Image buttons must have alternative text"
2424
},
2525
"all": [],
26-
"any": ["non-empty-alt", "aria-label", "aria-labelledby", "non-empty-title"],
26+
"any": [
27+
"non-empty-alt",
28+
"aria-label",
29+
"aria-labelledby",
30+
"non-empty-title",
31+
"implicit-label",
32+
"explicit-label"
33+
],
2734
"none": []
2835
}

locales/_template.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,8 @@
771771
"fail": "Element contains <img> element with alt text that duplicates existing text"
772772
},
773773
"explicit-label": {
774-
"pass": "Form element has an explicit <label>",
775-
"fail": "Form element does not have an explicit <label>",
774+
"pass": "Element has an explicit <label>",
775+
"fail": "Element does not have an explicit <label>",
776776
"incomplete": "Unable to determine if form element has an explicit <label>"
777777
},
778778
"help-same-as-label": {
@@ -785,8 +785,8 @@
785785
"incomplete": "Unable to determine if form element has explicit <label> that is hidden"
786786
},
787787
"implicit-label": {
788-
"pass": "Form element has an implicit (wrapped) <label>",
789-
"fail": "Form element does not have an implicit (wrapped) <label>",
788+
"pass": "Element has an implicit (wrapped) <label>",
789+
"fail": "Element does not have an implicit (wrapped) <label>",
790790
"incomplete": "Unable to determine if form element has an implicit (wrapped) <label>"
791791
},
792792
"label-content-name-mismatch": {

test/commons/text/native-text-methods.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ describe('text.nativeTextMethods', () => {
3939
const input = axe.utils.querySelectorAll(axe._tree[0], 'input')[0];
4040
assert.equal(buttonDefaultText(input), '');
4141
});
42+
43+
it('returns the default button text with mixed-case types', () => {
44+
fixtureSetup(
45+
'<input type="SUBMIT" />' +
46+
'<input type="ImAGE" />' +
47+
'<input type="ResET" />' +
48+
'<input type="buTTON" />'
49+
);
50+
const inputs = axe.utils.querySelectorAll(axe._tree[0], 'input');
51+
assert.equal(buttonDefaultText(inputs[0]), 'Submit');
52+
assert.equal(buttonDefaultText(inputs[1]), 'Submit');
53+
assert.equal(buttonDefaultText(inputs[2]), 'Reset');
54+
assert.equal(buttonDefaultText(inputs[3]), '');
55+
});
4256
});
4357

4458
describe('altText', () => {

test/integration/rules/button-name/button-name.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<button id="pass1" role="presentation" disabled></button>
2121
<button id="pass2" role="none" disabled></button>
2222

23+
<label>Name<button id="pass3"></button></label>
24+
<label for="pass4">Name</label>
25+
<button id="pass4"></button>
26+
2327
<span id="inapplicable1" role="button">Does not apply</span>
2428
<input type="submit" value="submit" role="button" id="inapplicable2" />
2529
<button id="inapplicable2" role="gridcell" disabled></button>

test/integration/rules/button-name/button-name.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
["#combo"],
2121
["#buttonTitle"],
2222
["#pass1"],
23-
["#pass2"]
23+
["#pass2"],
24+
["#pass3"],
25+
["#pass4"]
2426
]
2527
}

0 commit comments

Comments
 (0)