Skip to content

Commit 7c2ac4b

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

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-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 />"
2526
],
26-
invalid: ["<input type='text' />", "<textarea type='text'></textarea>"]
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+
}
35+
]
2736
});

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

+20-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,31 @@ const rule: Rule.RuleModule = {
3939
default:
4040
"Each form element must have a programmatically associated label element."
4141
},
42-
schema: []
42+
schema: [
43+
{
44+
type: "object",
45+
properties: {
46+
controlComponents: {
47+
type: "array",
48+
items: {
49+
type: "string"
50+
},
51+
uniqueItems: true
52+
}
53+
}
54+
}
55+
]
4356
},
4457
create(context) {
58+
const { controlComponents: customControlComponents = [] } =
59+
context.options[0] || {};
60+
61+
const controlComponents = ["input", "textarea", ...customControlComponents];
62+
4563
return defineTemplateBodyVisitor(context, {
4664
VElement(node) {
4765
const elementType = getElementType(node);
48-
if (!["input", "textarea"].includes(elementType)) {
66+
if (!controlComponents.includes(elementType)) {
4967
return;
5068
}
5169

0 commit comments

Comments
 (0)