-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
Fixes that the form field wasn't accounting for the case where the form control is swapped out. Fixes angular#29402.
this._initializeSubscript(); | ||
this._initializePrefixAndSuffix(); | ||
this._initializeOutlineLabelOffsetSubscriptions(); | ||
} | ||
|
||
ngAfterContentChecked() { | ||
this._assertFormFieldControl(); | ||
|
||
if (this._control !== this._previousControl) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes that the form field wasn't accounting for the case where the form control is swapped out.
Fixes #29402.