fix(820): check for all labelable elements

pull/5074/head
Bassam Ismail 5 years ago
parent c623b33ea3
commit 81ce352212

@ -61,6 +61,17 @@ const a11y_no_onchange = new Set([
'option' 'option'
]); ]);
const a11y_labelable = new Set([
"button",
"input",
"keygen",
"meter",
"output",
"progress",
"select",
"textarea"
]);
const invisible_elements = new Set(['meta', 'html', 'script', 'style']); const invisible_elements = new Set(['meta', 'html', 'script', 'style']);
const valid_modifiers = new Set([ const valid_modifiers = new Set([
@ -508,7 +519,7 @@ export default class Element extends Node {
} }
if (this.name === 'label') { if (this.name === 'label') {
const has_input_child = this.children.some(i => (i instanceof Element && i.name === 'input' )); const has_input_child = this.children.some(i => (i instanceof Element && a11y_labelable.has(i.name) ));
if (!attribute_map.has('for') && !has_input_child) { if (!attribute_map.has('for') && !has_input_child) {
component.warn(this, { component.warn(this, {
code: `a11y-label-has-associated-control`, code: `a11y-label-has-associated-control`,

@ -2,4 +2,5 @@
<label for="id">B</label> <label for="id">B</label>
<label>C <input type="text" /></label> <label>C <input type="text" /></label>
<label>D <span></span></label> <label>D <button>D</button></label>
<label>E <span></span></label>

@ -1,32 +1,32 @@
[ [
{ {
"code": "a11y-label-has-associated-control", "code": "a11y-label-has-associated-control",
"end": { "end": {
"character": 16, "character": 16,
"column": 16, "column": 16,
"line": 1 "line": 1
}, },
"message": "A11y: A form label must be associated with a control.", "message": "A11y: A form label must be associated with a control.",
"pos": 0, "pos": 0,
"start": { "start": {
"character": 0, "character": 0,
"column": 0, "column": 0,
"line": 1 "line": 1
} }
}, },
{ {
"code": "a11y-label-has-associated-control", "code": "a11y-label-has-associated-control",
"end": { "end": {
"character": 113, "character": 149,
"column": 30, "column": 30,
"line": 5 "line": 6
}, },
"message": "A11y: A form label must be associated with a control.", "message": "A11y: A form label must be associated with a control.",
"pos": 83, "pos": 119,
"start": { "start": {
"character": 83, "character": 119,
"column": 0, "column": 0,
"line": 5 "line": 6
} }
} }
] ]

Loading…
Cancel
Save