You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/label-has-for.md
+15-4Lines changed: 15 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,8 @@ This rule takes one optional object argument of type object:
20
20
"components": [ "Label" ],
21
21
"required": {
22
22
"every": [ "nesting", "id" ]
23
-
}
23
+
},
24
+
"allowChildren": false,
24
25
}],
25
26
}
26
27
}
@@ -53,14 +54,22 @@ return (
53
54
);
54
55
```
55
56
56
-
The `required` option (defaults to `"required": "id"`) determines which checks are activated. You're allowed to pass in one of the following types:
57
+
The `required` option (defaults to `"required": { "every": ["nesting", "id"] }`) determines which checks are activated. You're allowed to pass in one of the following types:
57
58
58
59
- string: must be one of the acceptable strings (`"nesting"` or `"id"`)
59
60
- object, must have one of the following properties:
60
61
61
62
- some: an array of acceptable strings, will pass if ANY of the requested checks passed
62
63
- every: an array of acceptable strings, will pass if ALL of the requested checks passed
63
64
65
+
The `allowChildren` option (defaults to `false`) determines whether `{children}` content is allowed to be passed into a `label` element. For example, the following pattern, by default, is not allowed:
66
+
67
+
```js
68
+
<label>{children}</label>
69
+
```
70
+
71
+
However, if `allowChildren` is set to `true`, no error will be raised. If you want to pass in `{children}` content without raising an error, because you cannot be sure what `{children}` will render, then set `allowChildren` to `true`.
72
+
64
73
Note that passing props as spread attribute without `htmlFor` explicitly defined will cause this rule to fail. Explicitly pass down `htmlFor` prop for rule to pass. The prop must have an actual value to pass. Use `Label` component above as a reference. **It is a good thing to explicitly pass props that you expect to be passed for self-documentation.** For example:
0 commit comments