Improve accessibility - associate label and fields #22361
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
The primary purpose of this change was to associate the labels on the event location form with the relevant inputs:
As part of this change, I have also updated the contact forms so that the "ext" text becomes a label for the relevant telephone extension fields.
Before
The labels "Email 1:", "Phone 1:", "Ext" did not have a
for
attribute, and so were not associated with theinput
elements. This wasn't the end of the world as there isaria-label
attributes in place, but adding the associations improves consistency, and means that mouse users can click on the labels to focus the relevant fields.After
The labels have
for
attributes and so are semantically linked with the relevant fields.Technical Details
I did consider just adding a hardcoded
for
attribute to the elements within the templates. However this seemed more brittle than using the style{$form.email.1.email.label}
. This does mean thatCRM_Contact_Form_Edit_Email::buildQuickForm
andCRM_Contact_Form_Edit_Phone::buildQuickForm
now set labels which may not be relevant to all scenarios where these methods are used. However I considered this ok, and any other contexts will simply ignore the labels unless they are explicitely rendered.