Skip to content

Commit c82af1e

Browse files
committed
✨ Allow custom form controls in form-control-has-label
Closes vue-a11y#373
1 parent 83d8f05 commit c82af1e

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

Diff for: src/rules/__tests__/form-control-has-label.test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ makeRuleTester("form-control-has-label", rule, {
2121
<div aria-hidden="true">
2222
<input value="1" type="text" />
2323
</div>
24-
`
24+
`,
25+
"<b-form-input />",
26+
],
27+
invalid: [
28+
"<input type='text' />",
29+
"<textarea type='text'></textarea>",
30+
{
31+
code: "<div><b-form-input /></div>",
32+
options: [{ controlComponents: ["b-form-input"] }],
33+
errors: [{ messageId: "default" }],
34+
},
2535
],
26-
invalid: ["<input type='text' />", "<textarea type='text'></textarea>"]
2736
});

Diff for: src/rules/form-control-has-label.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,30 @@ const rule: Rule.RuleModule = {
3939
default:
4040
"Each form element must have a programmatically associated label element."
4141
},
42-
schema: []
42+
schema: [{
43+
type: "object",
44+
properties: {
45+
controlComponents: {
46+
type: "array",
47+
items: {
48+
type: "string",
49+
},
50+
uniqueItems: true,
51+
},
52+
},
53+
}],
4354
},
4455
create(context) {
56+
const {
57+
controlComponents: customControlComponents = [],
58+
} = context.options[0] || {};
59+
60+
const controlComponents = ["input", "textarea", ...customControlComponents];
61+
4562
return defineTemplateBodyVisitor(context, {
4663
VElement(node) {
4764
const elementType = getElementType(node);
48-
if (!["input", "textarea"].includes(elementType)) {
65+
if (!controlComponents.includes(elementType)) {
4966
return;
5067
}
5168

0 commit comments

Comments
 (0)