Accessibility labels for form fields and fieldsets#805
Conversation
…plying fieldset to checkboxes/radios also changed the default form to not include any ID as that would cause invalid HTML if there are multiple forms on one page.
…el to wrap to new line for terms agreement
|
Changes: Tested:
|
| }), | ||
| ' ', | ||
| label | ||
| m('span', label) |
There was a problem hiding this comment.
Why do we wrap the label in <span> here now?
There was a problem hiding this comment.
if i don't, it puts on the same line as the already very long agree to terms text.
I tried to add ' ' and '\n' and that did nothing...
| ? field | ||
| : isNested | ||
| ? (hasLabel | ||
| ? m('label', [config.label, field]) |
There was a problem hiding this comment.
Should we include a <span> or something here to make it a tiny bit easier to style the label text or have it be on a separate line from the field by default?
I think a lot of themes used to have display: block on the <label> element, resulting in a neat line-break between the label text and the input field. After this change, a lot of themes will have the input field on the same line as the label unless their input is display: block.
We should also check the CSS themes we ship to see what we're doing.
There was a problem hiding this comment.
and styles builder possibly as well, will click around
There was a problem hiding this comment.
added the span around text inside the label
made some changes to the default themes but warrants more testing.
also need to update the styles builder
…Also some CSS changes to target that span instead of label
|
I've put it back in draft mode now that I realize we have to update the styles builder too |
|
reminder for myself that the CSS changes also need to keep the old css in place for existing forms. |
Also made change to your last edit in form-generator to prevent a js error when adding fields and changed the default form content to be consistent.
|
@dannyvankooten in my test setup your changes to field-generator caused a JS error when trying to add a field: So i changed that to if (config.min !== undefined && config.min.length) { ... I'm pretty sure I got th CSS down for both new and old style, using > and + to cover the different situation for the field inside and outside the label. Now the only small little detail is the CSS output of the styles builder in the Premium add-on... :) |
|
so we will always have the issue of Premium add-on being "out of sync" with this sort of update, I think the best solution we can offer is first publishing the Premium add-on update, wait a bit and then publish this update? That is the main reason for me to leave this on draft for now, besides it still warranting some more testing I suppose. |
There was a problem hiding this comment.
Pull request overview
This PR improves generated Mailchimp form accessibility by associating labels implicitly and grouping checkbox/radio choices with fieldsets.
Changes:
- Wraps generated text/select inputs inside labels when labels are shown.
- Wraps checkbox/radio groups in fieldsets with legends.
- Updates basic/theme CSS for nested input layouts.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
assets/src/js/admin/form-editor/field-generator.js |
Changes generated markup for labels, inputs, checkbox/radio groups, and wrapping behavior. |
assets/src/js/admin/form-editor/field-forms.js |
Adjusts editor options shown for choice fields. |
assets/src/css/form-basic.css |
Updates basic form styling for nested inputs. |
assets/src/css/form-themes.css |
Updates themed form styling for nested inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (config.label && config.showLabel) { | ||
| return m('label', [ | ||
| config.label, | ||
| m('input', attributes) | ||
| ]) |
| return m('fieldset', [ | ||
| config.label && config.showLabel ? m('legend', config.label) : null, |
| } | ||
|
|
||
| if (config.type === 'select' || config.type === 'radio') { | ||
| if (config.type === 'select') { |
| /* NEW STYLE: When input is nested inside label */ | ||
| .mc4wp-form-basic label > input { |
| } | ||
|
|
||
| /* NEW STYLE: When input is nested inside label */ | ||
| .mc4wp-form-theme label > input { |
What I changed and tested > see comment below.
I propose to wrap every input in its label, that way we don't need to deal with ID's
this way we prevent any issues with duplicated IDs and are still w3c accessible compliant by Associating labels implicitly
https://www.w3.org/WAI/tutorials/forms/labels/#using-aria-label
to this end I
Removed the ID from the default form content
Wrapped inputs in their label
Added "fieldset" around checkbox and radios with the agree to terms excluded as that has only 1 choice it can still be wrapped in label
removed the wrap in P option for "fieldset" as a fieldset will close the p / can't be wrapped in p
this would close Small tweak for accessibility (currently fails two WCAG guidelines) #640