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
Conversation
ed4b79f
to
8958485
Compare
Current coverage is 91.49% (diff: 100%)@@ 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
|
/> | ||
); | ||
}); | ||
|
||
const value = String(_.get(profile, keySet)); | ||
return ( | ||
<div className={validationErrorSelector(errors, keySet)}> | ||
<div | ||
role="group" |
There was a problem hiding this comment.
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".
In order for this to be properly accessible, these three |
@@ -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}`; |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 RadioButton
s 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.
There was a problem hiding this comment.
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.
@singingwolfboy if you'd like to take over review on this feel free to reassign |
8958485
to
145a638
Compare
@singingwolfboy I updated to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, I think I accidentally forgot to add the right class back onto the |
145a638
to
5351b2e
Compare
just added it back real quick |
Now the labels for the radio buttons are no longer bold, but all the dropdown menus still are bold. |
oh that was a silly CSS error. two seconds. |
All better! |
4c244e6
to
0be9d6c
Compare
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.