jxom / fannypack

[UNMAINTAINED] An accessible-focused, themeable, friendly React UI Kit.
https://fannypack.style
MIT License
235 stars 29 forks source link

Fix/A11Y Fannypack/Checkbox #111

Closed danielagattoni closed 4 years ago

danielagattoni commented 4 years ago

Problem:

Currently, if I want to use screen Reader to navigate the checkbox, Its Label "Receive newsletter" is not being read as expected on a usual native Checkbox implementation.

Current Fannypack/Checkbox Unchecked state:

Screen Shot 2020-03-17 at 4 55 52 pm

Current Fannypack/Checkbox Checked state:

Screen Shot 2020-03-17 at 4 55 58 pm

Example via https://codesandbox.io/s/a11y-example-1-checkboxes-9h49e

Some Context on Semantic Checkboxes:

Example 1 where <label> is wrapping the input and text:

 <label>
          <input type="checkbox" id="newsletter" />
          Receive Newsletter 
 </label>

Example 2 where htmlFor associates the input with the label:

 <input type="checkbox" id="newsletter" />
 <label htmlFor="newsletter">Receive Newsletter</label>

The issue seems like the Fannypack/Checkbox is mixing both techniques, and also adding unnecessary aria-label. We can sort out the Accessibility following one of the two examples described above, and keep aria-label for other custom widgets, such as accordions and custom-made buttons.

My suggested solution:

In order to follow example 1 approach (label wrapping input and text) I have made a few changes in the Checkbox component. so the result can be test on the screenshot below, where the screen Reader now is able to describe the Label text AND State on the focused checkbox.

Initial State:

Screen Shot 2020-03-17 at 4 38 54 pm

Checked:

Screen Shot 2020-03-17 at 4 39 02 pm

Unchecked:

Screen Shot 2020-03-17 at 4 39 05 pm
linc[bot] commented 4 years ago

Preview releases deployed with Linc logo Linc

✅ This PR (commit SHA 2ee56d8) successfully built (bundle ID a71324fc4)  VIEW LOGS

🌏 Permanent preview links of latest version on this branch:  EDIT

https://fannypack--develop--fixa11y-checkbox.branch.linc-preview.sh/
https://fannypack--production--fixa11y-checkbox.branch.linc-preview.sh/

See older previews from this branch