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

Move input inside labels in radios and checkboxes #114

Open
gustavoguichard opened this issue Dec 2, 2022 · 0 comments
Open

Move input inside labels in radios and checkboxes #114

gustavoguichard opened this issue Dec 2, 2022 · 0 comments
Labels
enhancement New feature or request planned for v3

Comments

@gustavoguichard
Copy link
Contributor

gustavoguichard commented Dec 2, 2022

It is a common practice to use this structure for radios and inputs:

<label>
  <input type="checkbox" />
  Check it out
</label>

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

Source: MDN

It also gives another benefit:
Screenshot_2022-12-02_at_10_03_15

Clicking in areas in between the checkbox and the label will work to toggle the input.
If you try to do it now in the site examples you'll see there are some blind areas.

Another tip since we are talking about it. I usually add this line to my CSS:

label[for], li:has(> input)  {
  cursor: pointer;
}

Therefore the cursor will be already suggesting a click whenever you use either approach:

<label><input /></label>

<!-- or -->

<label for="foo" /><input id="foo" />
@danielweinmann danielweinmann added the enhancement New feature or request label Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request planned for v3
Projects
None yet
Development

No branches or pull requests

2 participants