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

bug(mat-form-field): CSS class generated by controlType of MatFormFieldControl is static, never changes if the control changes #29402

Closed
1 task
robmv opened this issue Jul 9, 2024 · 1 comment · Fixed by #29573
Assignees
Labels
area: material/form-field P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@robmv
Copy link

robmv commented Jul 9, 2024

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

mat-form-field is able to generate a CSS class based on the value of MatFormFieldControl's controlType. The problem is that when the MatFormFieldControl implementation changes dynamically the field always has the initial MatFormFieldControl CSS class, for example if the initial control is a mat-input and later changes to a mat-select the CSS class on the field will always be mat-mdc-form-field-type-mat-input

Note: The documentation says the prefix for the generated CSS class is mat-form-field-type but the real ones have the prefix mat-mdc-form-field-type. This could be a documentation bug or a regression from the legacy controls, but the prefix is a different bug that this one I am reporting.

Reproduction

StackBlitz link: https://stackblitz.com/edit/qbaesq

Steps to reproduce:

  1. The demo shows two fields one that initially uses a mat-input and the other a mat-select
  2. The button on the top switch the implementations of MatFormFieldControl used on the fields
  3. After the switch an error is shown below each field, the error is a check that the field contains the correct CSS class for the control implementation.

Expected Behavior

No error should be shown because each field switch dynamically the control generated CSS class.

Actual Behavior

Fields don't change to the control CSS class dynamically, it always stays on the same initial class.

Environment

  • Angular: 18.0.6
  • CDK/Material: 18.0.6
  • Browser(s): Firefox, Chromium
  • Operating System (e.g. Windows, macOS, Ubuntu): Linux (Fedora)
@robmv robmv added the needs triage This issue needs to be triaged by the team label Jul 9, 2024
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: material/form-field and removed needs triage This issue needs to be triaged by the team labels Jul 10, 2024
@crisbeto crisbeto self-assigned this Aug 12, 2024
crisbeto added a commit to crisbeto/material2 that referenced this issue Aug 12, 2024
Fixes that the form field wasn't accounting for the case where the form control is swapped out.

Fixes angular#29402.
crisbeto added a commit that referenced this issue Aug 13, 2024
Fixes that the form field wasn't accounting for the case where the form control is swapped out.

Fixes #29402.
crisbeto added a commit that referenced this issue 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 issue 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
area: material/form-field P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants