clari / react-ios-switch

React switch component https://clari.github.io/react-ios-switch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

a11y for input and allowing additional props

Pharserror opened this issue · comments

a11y compliance for inputs requires that all inputs have a <label> with a for attribute that points to the ID of the <input> element or that the <input> element has an aria-label or aria-labelledby attribute.

The goal of this PR is to introduce the options for those attributes on the input. To be more specific:

  1. To allow an id attribute on the <input> if one is passed in through an inputId prop on a <Switch> component.
  2. To allow an aria-label attribute on the <input> if one is passed in through an inputAria.label prop on a <Switch> component.
  3. To allow an aria-labelledby attribute on the <input> if one is passed in through an inputAria.labelledby prop on a <Switch> component.

I believe the best way to achieve this is to call the prop for the input id inputId just to be more specific than simply id in order to communicate that this prop will specifically be used to set the id attribute of the <input>. Similarly, I believe that nesting the ARIA-specific properties for the input in an object inputAria for those same reasons is also the best choice of action in this case.

@mking-clari any progress on fixing this issue?

To add onto this, it should also be following:
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Switch_role

aria-checked when checked, it should also have a role of switch (role="switch"). Ideally it should be a button, but since its not it should listen to Enter and (space) keystrokes.

I created a PR for this issue
#12