Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/form-field): update state if control changes #29573

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

crisbeto
Copy link
Member

Fixes that the form field wasn't accounting for the case where the form control is swapped out.

Fixes #29402.

Fixes that the form field wasn't accounting for the case where the form control is swapped out.

Fixes angular#29402.
@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Aug 12, 2024
@crisbeto crisbeto requested a review from a team as a code owner August 12, 2024 12:54
@crisbeto crisbeto requested review from mmalerba and andrewseguin and removed request for a team August 12, 2024 12:54
this._initializeSubscript();
this._initializePrefixAndSuffix();
this._initializeOutlineLabelOffsetSubscriptions();
}

ngAfterContentChecked() {
this._assertFormFieldControl();

if (this._control !== this._previousControl) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Another option for this would've been to use signals, but it seems like _control is set up as some sort of backwards compatibility layer so I didn't want to change it into a computed which would've been breaking.

@@ -409,25 +418,31 @@ export class MatFormField
}

/** Initializes the registered form field control. */
private _initializeControl() {
private _initializeControl(previousControl: MatFormFieldControl<unknown> | null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why pass previousControl in, can't we just read it off the class like we do for control?

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 wanted to keep the code that re-assigns it in the ngAfterContentChecked since that's the only place where we check it.

@crisbeto crisbeto removed the request for review from andrewseguin August 13, 2024 06:09
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Aug 13, 2024
@crisbeto crisbeto merged commit ec35e99 into angular:main Aug 13, 2024
23 of 25 checks passed
crisbeto added a commit that referenced this pull request Aug 13, 2024
Fixes that the form field wasn't accounting for the case where the form control is swapped out.

Fixes #29402.

(cherry picked from commit ec35e99)
crisbeto added a commit that referenced this pull request Aug 13, 2024
Fixes that the form field wasn't accounting for the case where the form control is swapped out.

Fixes #29402.

(cherry picked from commit ec35e99)
@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 Sep 13, 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 target: patch This PR is targeted for the next patch release
Projects
None yet
2 participants