Skip to content

MudBaseInput: match inputs id with label's for attribute (#6249, #6460)#8672

Merged
henon merged 7 commits intoMudBlazor:devfrom
igotinfected:feature/mudtextfield-match-label-id-when-present
Apr 18, 2024
Merged

MudBaseInput: match inputs id with label's for attribute (#6249, #6460)#8672
henon merged 7 commits intoMudBlazor:devfrom
igotinfected:feature/mudtextfield-match-label-id-when-present

Conversation

@igotinfected
Copy link
Member

@igotinfected igotinfected commented Apr 12, 2024

Description

Warning

Disclaimer: I am not an accessibility expert. As mentioned in a different discussion: I'm interested in improving the accessibility of MudBlazor for work because we are subject to accessibility audits.

This PR improves input <-> label accessibility by ensuring ids provided to inputs and labels are equal and always present.

These changes affect the following components: MudTextField, MudNumericField, MudAutocomplete, MudSelect, MudColorPicker, MudDatePicker, MudTimePicker

The general logic is that the MudBlazor component generates its own id (or uses the user provided one, in this order: UserAttributes > InputId > auto generated id) and passes it down to the controls that render input and label.

Fixes #6249, fixes #6460

How Has This Been Tested?

Unit tests for affected components and the chrome issues tab + axe devtools for before/after comparison, e.g.:

mudtextfield-chrome-issues mudtextfield-axe-devtools

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added breaking change This change will require consumer code updates bug Unexpected behavior or functionality not working as intended enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library PR: needs review labels Apr 12, 2024
@codecov
Copy link

codecov bot commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.09%. Comparing base (28bc599) to head (4448a5e).
Report is 55 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8672      +/-   ##
==========================================
+ Coverage   89.82%   90.09%   +0.26%     
==========================================
  Files         412      418       +6     
  Lines       11878    12055     +177     
  Branches     2364     2365       +1     
==========================================
+ Hits        10670    10861     +191     
+ Misses        681      660      -21     
- Partials      527      534       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@igotinfected
Copy link
Member Author

@ScarletKuro @henon for review, not sure whether this can be considered a breaking change since this messes with input ids (and affected inputs no longer use FieldId from MudComponentBase)

Potential next steps:

I saw the FieldId property on MudComponentBase but out of hundreds of inheritors of MudComponentBase the components affected by this PR and MudField + MudDateRangePicker are the only ones that use(d) it.

MudField is not necessarily a form control. According to the documentation it can be used for static text (in this case it must not have a label tag) or it can be used to create custom form controls (in this case it must have a label tag). The API should most likely allow the user to decide whether a label tag or some other text container should be used for the Label property.

Currently it always has a label tag, which triggers accessibility issues:

image

MudDateRangePicker is a bit of a special case, it has two inputs (one for start date, one for end date). It should therefore probably have two labels (they can probably be hidden visually but still visible for a screen reader, that seems to be the right approach). The currently visible label might need to be replaced with a different text container.

image

@Anu6is
Copy link
Contributor

Anu6is commented Apr 12, 2024

Couldn't you have added FieldId as the id for the <input>, given that it was already used for the ForId. Why add CalculatedFieldId and the additional InputId parameter.

I suppose the InputId makes adding an id slightly more discoverable?

@igotinfected
Copy link
Member Author

igotinfected commented Apr 12, 2024

Couldn't you have added FieldId as the id for the <input>, given that it was already used for the ForId. Why add CalculatedFieldId and the additional InputId parameter.

I suppose the InputId makes adding an id slightly more discoverable?

I think FieldId should be removed from MudComponentBase since only a limited subset of inheritors actually need it, basically only the components affected by this PR and MudField + MudDateRangePicker (both of which need their own adjustments for label/id accessibility issues).

The InputId is an extra, though yeah it seems more user friendly than <MudTextField id="my-custom-id" .../>

Edit: because you have to know the inner workings of the components to know that id will be applied to the input tag

Copy link
Member

@danielchalmers danielchalmers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this work in a very important area!!

Breaking changes are ok; If you think FieldId can be removed in a beneficial way it should be explored.

@ScarletKuro
Copy link
Member

Breaking changes are ok; If you think FieldId can be removed in a beneficial way it should be explored.

Don't have an opinion on that, as I don't know much accessibility flow, can only link a PR that added it #4107 and that i was also for the WCAG

@henon
Copy link
Contributor

henon commented Apr 13, 2024

@brianseim If you could review this change, we'd appreciate it a lot.

@henon
Copy link
Contributor

henon commented Apr 16, 2024

This is marked as breaking change but I don't understand what exactly got broken. Can you summarize for the migration guide?

@igotinfected
Copy link
Member Author

This is marked as breaking change but I don't understand what exactly got broken. Can you summarize for the migration guide?

I think I was worried about the userAttributes id being overwritten (or no longer using FieldId) when I first published the PR. I've just reviewed the code and I don't see any breaking change anymore. Should be safe to remove the tag (and sorry for not stating the reason for marking it as breaking change in the first place!).

@henon henon removed breaking change This change will require consumer code updates PR: needs review labels Apr 18, 2024
@henon henon merged commit 31d24c4 into MudBlazor:dev Apr 18, 2024
@henon
Copy link
Contributor

henon commented Apr 18, 2024

Thanks

@igotinfected igotinfected deleted the feature/mudtextfield-match-label-id-when-present branch April 18, 2024 19:19
biegehydra pushed a commit to biegehydra/MudBlazor that referenced this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The ID attribute is not set on the underlying input element for a MudSelect MudTextField not having id set when accompanying label has for attribute

5 participants