microsoft / tslint-microsoft-contrib

A set of TSLint rules used on some Microsoft projects.
MIT License
702 stars 198 forks source link

new a11y rule: Labels must be explicitly associated with their controls #271

Closed HamletDRC closed 5 years ago

HamletDRC commented 8 years ago

"A label is implicitly associated with its form control either through markup or positioning on the page."

<LABEL for="firstname">First name: 
    <INPUT type="text" id="firstname" tabindex="1">
</LABEL>

references

    <label for="favoritecolor">Your Favorite Color</label>
    <input name="FavoriteColor" type="text" id="favoritecolor" />

"For checkboxes and radio buttons, use the

and elements to get everything labeled properly."

<fieldset>
  <legend>Your Favorite Color</legend>
  <input type=”radio” name=”favoritecolor” value=”blue” id=”  blue”>
  <label for=”blue”>Blue</label>
  <input type=”radio” name=”favoritecolor” value=”green” id=”green”>
  <label for=”green”>Green</label>
  <input type=”radio” name=”favoritecolor” value=”purple” id=”purple”>
  <label for=”purple”>Purple</label>
</fieldset>

From https://github.com/globant-ui/arialinter/blob/master/lib/rules/inputAssistance.js:

From HTML Code Sniffer (https://squizlabs.github.io/HTML_CodeSniffer/Standards/WCAG2/):

Use title when label not available: https://www.w3.org/TR/2015/NOTE-WCAG20-TECHS-20150226/H65"The objective of this technique is to use the title attribute to label form controls when the visual design cannot accommodate the label"

<input id="areaCode" name="areaCode" title="Area Code" type="text" size="3" value="" >

or

<input type="text" title="Type search term here"/>

Form does not contain a submit button (input type="submit", input type="image", or button type="submit").

From HTML Code Sniffer SC 4.1.2: Name, Role, Value (Level A)

  • http://www.w3.org/TR/WCAG20-TECHS/H91
  • Form control which does not have a valid accessibility API "name". The message states which items count as a valid "name".
  • Form control which does not have a valid accessibility API "value". The message states how to add a valid value.

input type="checkbox" elements must have a group and that that group designation must be consistent - axe-core checkboxgroup. Ensure related input type="radio" elements have a group and that the group designation is consistent - axe-core radiogroup

astorije commented 6 years ago

For the record, the ESLint equivalent of this is label-has-associated-control, formerly known as label-has-for.

JoshuaKGoldberg commented 5 years ago

💀 It's time! 💀

TSLint is being deprecated; therefore, it and tslint-microsoft-contrib are no longer accepting pull requests for major new changes or features. See https://github.com/palantir/tslint/issues/4534. 😱

If you'd like to see this change implemented, you have two choices:

👋 It was a pleasure open sourcing with you!

If you believe this message was posted here in error, please comment so we can re-open the issue!