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

[label-has-associated-control] add button to list of elements that can be associated with a label #991

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

huynhducduy
Copy link

According to Mdn Web Docs, button is one of the elements that can be associated with label

This PR add button to the list.

@ljharb
Copy link
Member

ljharb commented Jun 12, 2024

While that's technically true, what would be the point of putting a label on a button, when you can just put the label contents inside the button?

@huynhducduy
Copy link
Author

huynhducduy commented Jun 13, 2024

While that's technically true, what would be the point of putting a label on a button, when you can just put the label contents inside the button?

The simplest thing I can think of is to make use of the for attribute to set the label for another element. While this is not recommended and may interfere with assistive technology.

Perhaps we should let this rule follow the spec, and create another rule to disapprove the use of interactive elements like a, button, and headings inside the label.

@ljharb
Copy link
Member

ljharb commented Jun 13, 2024

The spec isn't the important thing to follow here, though - accessibility is. Our linter rules should forbid standard things that don't increase a11y, and should require nonstandard things if they do increase a11y.

@huynhducduy
Copy link
Author

Oh, if that is the case, then we have more things to do in this rule as well (as stated in https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#accessibility_concerns)

  • disallow button and input with type=button
  • disallow interactive elements
  • disallow headings in favor of legend and fieldset
  • ...maybe more

And those should explicitly mentioned in the document as well

@ljharb
Copy link
Member

ljharb commented Jun 14, 2024

Sounds good.

@huynhducduy
Copy link
Author

Alright, should I close this PR and open an issue for further discussion, then work on it via a future PR, or can I just keep this PR?

@ljharb
Copy link
Member

ljharb commented Jun 14, 2024

If this PR can be repurposed, that's ideal; if not, close it and file new ones.

@ljharb ljharb marked this pull request as draft September 4, 2024 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants