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

making the gender radio buttons more accessible #1964

Merged
merged 1 commit into from Dec 12, 2016

Conversation

alicewriteswrongs
Copy link
Contributor

What are the relevant tickets?

closes #1849

What's this PR do?

Hopefully this makes the gender radio buttons more accessible, by giving them proper labels and so on.

@singingwolfboy I would love to get your feedback on this, since I'm not sure this is the proper way to address this. MaterialUI is a bit frustrating to deal with here.

@codecov-io
Copy link

codecov-io commented Dec 5, 2016

Current coverage is 91.49% (diff: 100%)

Merging #1964 into master will decrease coverage by <.01%

@@             master      #1964   diff @@
==========================================
  Files           290        290          
  Lines         20631      20635     +4   
  Methods        2508       2510     +2   
  Messages          0          0          
  Branches       1826       1825     -1   
==========================================
+ Hits          18877      18879     +2   
+ Misses         1726       1724     -2   
- Partials         28         32     +4   

Powered by Codecov. Last update d62fd53...5351b2e

/>
);
});

const value = String(_.get(profile, keySet));
return (
<div className={validationErrorSelector(errors, keySet)}>
<div
role="group"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think radiogroup would be better here. Could you also add a aria-labelledby attribute here that points to the profile-radio-group-label just below? That will make screen readers will annoucne this section as "Gender Radio Button Group".

@singingwolfboy
Copy link
Contributor

In order for this to be properly accessible, these three <input> elements need to be wrapped inside of a <fieldset> element, with a <legend> element that describes the choice that the user is making. As an example, notice how the day/month/year fields are wrapped in a <fieldset> with a <legend> element, to inform screen readers that these three fields are all closely related to each other.

@@ -48,8 +48,9 @@ export function boundRadioGroupField(keySet: string[], label: string, options: O
if (obj.helper) {
helper = `${obj.helper}`;
}
let labelId = `gender-option-${obj.label}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work properly if obj.label has spaces in it, such as "Other/Prefer not to say".

@@ -62,13 +63,17 @@ export function boundRadioGroupField(keySet: string[], label: string, options: O
labelStyle={styles.labelStyle}
value={obj.value}
label={label}
aria-labelledby={labelId}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use a <label> element rather than aria-labelledby if possible. You can nest the <input> element inside of the <label> element, or use the for attribute on the label to point to the element ID that is being labelled. Using <label> also makes the browser automatically understand that when the user clicks on the label text, the <input> field should be selected -- although it looks like Material UI is manually recreating that behavior using Javascript.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

material-ui is a whole ball of wax here...I'll wrap the RadioButton in a label tag, since when you pass the label prop in to RadioButton it doesn't seem to get properly connected to the input.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I don't think we can do something like:

<label>
  A label
  <RadioButton
    prop={val}
  />
</label>

because we render those RadioButtons as the children of a RadioButtonGroup. RadioButtonGroup assumes that all of it's children are RadioButton elements at the top level...annoying.

Not sure what to do here. When I set the label attribute on RadioButton it doesn't render the input inside of the label element OR use aria-labelledby to point the screenreader to the appropriate label, at least as far as I can tell. Anyway, tryna figure out what to do here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I ended up doing is passing a React element to the label prop on RadioButton, which is then rendered sort of next to it. I can then set aria-labelledby on the actual input in order to point to that label.

@rhysyngsun
Copy link
Contributor

@singingwolfboy if you'd like to take over review on this feel free to reassign

@alicewriteswrongs
Copy link
Contributor Author

@singingwolfboy I updated to use <fieldset> and <legend> elements, let me know what you think!

Copy link
Contributor

@singingwolfboy singingwolfboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works great from an accessibility point of view: a screen reader reads out the radio buttons perfectly. However, the labels are bold now -- is that intentional? Is that something that might be resolved just by rebasing onto master?
bold-labels

@alicewriteswrongs
Copy link
Contributor Author

oops, I think I accidentally forgot to add the right class back onto the label element.

@alicewriteswrongs
Copy link
Contributor Author

just added it back real quick

@singingwolfboy
Copy link
Contributor

Now the labels for the radio buttons are no longer bold, but all the dropdown menus still are bold.

@alicewriteswrongs
Copy link
Contributor Author

oh that was a silly CSS error. two seconds.

@singingwolfboy
Copy link
Contributor

All better!

This wraps the whole affair with a `<fieldset>` tag, adds a legend, and
ensures that each option has a label that is associated with it.

closes #1849
pr #1964
@alicewriteswrongs alicewriteswrongs merged commit 0be9d6c into master Dec 12, 2016
@alicewriteswrongs alicewriteswrongs deleted the ap/accessible-gender branch December 12, 2016 19:04
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci December 12, 2016 19:15 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sign up: gender radio buttons not accessible
5 participants