Problem/Motivation
The radios
elements that are provided by core do not apply the required
attribute to the generated <input>
elements. Instead the required
attribute is applied to the wrapping <fieldset>
.
There are two issues with this:
- screen readers use
required
attribute on<input type="radio">
. If the attribute is not present on the , then the required state will not be communicated to the screen reader user. - the
required
attribute is not valid when applied to a<fieldset>
, thus causing the page to fail W3C validation.
Proposed resolution
- Remove the
required
andaria-required
attributes from the<fieldset>
of Form API radios elements. - Add
required
attribute to the<input type=radio>
elements instead. - CSS updates, to ensure no visual regression in Seven and Bartik.
Remaining tasks
- Remove
required
+ andaria-required
attributes from the<fieldset>
element to the<input>
element. DONE. Add therequired="required"<code> attribute to the <code><input type="radio">
elements.- CSS to avoid visual regression. Asterisk should be after the fieldset legend, not the individual radio buttons.
- Evaluate impact on Classy - Can the CSS go into Classy? - Classy is removed from D10 so may be non issue
Tests?Appear to have been added
Manual testing tips
We need a required radios element to test this, e.g. add a "favourite colour" field to a content type. Use a field of type "List", mark it required, and use the radios/checkboxes widget under "manage form display".
User interface changes
Markup + CSS changes to
- Fix invalid HTML
- Convey required radio buttons correctly to assistive tech.
- Avoid visual regression.
API changes
None.
Data model changes
None.
Original report by @mfairchild365
This issue is split off from #2950999: Checkboxes element missing "required" attribute. That issue originally addressed radios and checkboxes, but it looks like they need different solutions, so we're using separate issues now.