Skip to content

Conversation

crisbeto
Copy link
Member

Includes the following fixes for how we deal with ariab-describedby in the form field:

fix(material/form-field): avoid touching the DOM on each state change

Currently we set the aria-describedby every time the state of the form control changes. This is excessive, because it only needs to happen if the error state or userAriaDescribedBy change.

fix(material/input): preserve aria-describedby set externally

Currently there are two sources of an aria-describedby for a matInput: the IDs of the hint/error message in the form field and any custom ones set through aria-describedby. This is insufficient, because the ID can also come from a direct DOM manipulation like in the AriaDescriber.

These changes tweak the logic to try and preserve them, because currently they get overwritten.

Fixes #30011.

Currently we set the `aria-describedby` every time the state of the form control changes. This is excessive, because it only needs to happen if the error state or `userAriaDescribedBy` change.
Currently there are two sources of an `aria-describedby` for a `matInput`: the IDs of the hint/error message in the form field and any custom ones set through `aria-describedby`. This is insufficient, because the ID can also come from a direct DOM manupulation like in the `AriaDescriber`.

These changes tweak the logic to try and preserve them, because currently they get overwritten.

Fixes angular#30011.
@crisbeto crisbeto added the target: rc This PR is targeted for the next release-candidate label Nov 14, 2024
@crisbeto crisbeto requested a review from a team as a code owner November 14, 2024 12:37
@crisbeto crisbeto requested review from andrewseguin and mmalerba and removed request for a team November 14, 2024 12:37

// Updating the `aria-describedby` touches the DOM. Only do it if it actually needs to change.
this._describedByChanges?.unsubscribe();
this._describedByChanges = control.stateChanges
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried basing this on top of signals, but the timing was off because I had to run _syncDescribedByIds in an effect.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we'll do a bigger refactor at some point and replace syncDescribedByIds with a signal, describedByIds

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I'd argue pretty much all the properties in the FormFieldControl should be signals.

@crisbeto crisbeto removed the request for review from andrewseguin November 14, 2024 16:22
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker merge: preserve commits When the PR is merged, a rebase and merge should be performed labels Nov 14, 2024
@crisbeto crisbeto merged commit 9db29c9 into angular:main Nov 14, 2024
24 of 26 checks passed
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker merge: preserve commits When the PR is merged, a rebase and merge should be performed target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(mat-form-field): Form field removes aria-describedby attribute added by AriaDescriber

2 participants