Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input-requires-label rule should allow input tag nested inside label tag #1170

Open
at6ue opened this issue Sep 19, 2022 · 2 comments
Open
Labels
help wanted We are looking for community help keep-unstale The issue will not be marked as stale by the stale-bot PR needed rule Relates to HTMLHint's core rules

Comments

@at6ue
Copy link

at6ue commented Sep 19, 2022

Currently, the input-requires-label rule forces the input tag to have an id attribute to associate a label tag, but the input tag without id attribute can be considered to be associated with a nesting label tag.

Alternatively, you can nest the <input> directly inside the <label>, in which case the for and id attributes are not needed because the association is implicit:
<label>: The Input Label element - HTML: HyperText Markup Language | MDN

According to HTML Standard,

If the for attribute is not specified, but the label element has a labelable element descendant, then the first such descendant in tree order is the label element's labeled control.

So, my idea is to modify the rule to allow the first input tag nested inside a label tag without the for attribute.

Here is a small example: clicking on the "bar" label toggles the "baz" checkbox associated with the for attribute, instead of the nested "bar" checkbox.
https://jsfiddle.net/pL5s0mvk/

@nschonni
Copy link
Contributor

Yes, the wrapping is valid, so you don't need to turn on this rule if you're using that style. All rules are opt-in

@coliff coliff changed the title input-requires-label rule should allow input tag nested inside label tag input-requires-label rule should allow input tag nested inside label tag Sep 20, 2022
@at6ue
Copy link
Author

at6ue commented Sep 23, 2022

Unfortunately, our codebase has both styles, so for the moment we ignore warnings against nested input tags.

Is the rule open for modification on that point? If yes, I or someone else can consider sending a PR.

@coliff coliff added PR needed help wanted We are looking for community help keep-unstale The issue will not be marked as stale by the stale-bot rule Relates to HTMLHint's core rules labels Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We are looking for community help keep-unstale The issue will not be marked as stale by the stale-bot PR needed rule Relates to HTMLHint's core rules
Projects
None yet
Development

No branches or pull requests

3 participants