[Outreachy Task Submission] Form Inputs Are Disconnected From Their Labels #985
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.
Should resolve #4904
Description
Currently, most of all the form inputs fields on the Ushahidi platform are disconnected from their labels and this makes it difficult for screen readers to understand the purpose of the input field, so when the input is focused the screen reader just announces the html element and in some cases it relies on the input placeholder.
Given the Ushahidi's platform data-driven nature and heavy reliance on forms, it is of high priority to ensure that forms are fully accessible in order to create a more inclusive environment, facilitating seamless interaction for all users, regardless of their accessibility needs.
How to reproduce?
label
is linked to the input?See image below 👇🏽
Why does this happen?
After digging very deep into this, I realized that the
mat-label
s are currently placed outside of themat-form-field
to prevent the default material form input animation that happens when themat-label
is placed inside themat-form-field
. This works fine aesthetically and matches the design but the disadvantage is that it disconnects the labels from their inputs, leaving these fields without labels and even aria-labels attributes thereby making it difficult for screen readers to understand.How to fix this
There are two ways to fix this:
mat-label
back inside themat-form-field
element and use the method described here in the angular material docs along some extra styling to keep the label fixed at the top of the input.mat-label
I have chosen to go with option 2 to fix this issue because of the following reasons
mat-label
component.. in other words less use of!important
:)The one caveat that comes with this approach is, semantic labels won't work on other material components like
mat-select
,mat-selection-list
but for this I have chosen to rely onaria-label
attribute which works perfectly and is also recommended in the angular material ui v14 doc@Angamanga This is another promising and very important pr as it'll involve making changes to all the forms on the Ushahidi web codebase and I'll need your feedback/approval to continue with this. 🙏🏽