angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.34k stars 6.74k forks source link

bug: Custom Form Controls not updating touch state changes from API #29750

Open eLarocque opened 1 month ago

eLarocque commented 1 month ago

Is this a regression?

The previous version in which this bug was not present was

No response

Description

My custom form controls do not support the FormControl APIs for things related to the touch state.

Specific use case: I am attempting to reset a form control after it has been touched, but the "touched" states are not reset, which makes any previous error states persist.

Comparing with built in controls like matInput, we can see the differences and reproduce this issue. I have modified the latest Angular Material Stackblitz example (taken from https://v18.material.angular.io/guide/creating-a-custom-form-field-control) and added a matInput control side by side with the custom Telephone control

Maybe it is possible to handle these cases but the example on the official docs do not reflect that possiblity...

Reproduction

StackBlitz link: https://stackblitz.com/edit/sjcjgs-bpf7wt

Steps to reproduce: You can see 2 issues in this example: 1) The custom form control ignores the API call markAsTouched, whereas the matInput does not.

Steps:

2) After manually touching the custom form control, it ignores the API call reset, whereas the matInput does not.

Steps:

Expected Behavior

Should be able to set / reset touched state using the FormControl API on Custom Form Controls

Actual Behavior

The touched stats is never updated

Environment

crisbeto commented 1 week ago

This likely has more to do with the errorState getter than the forms integration.

Sepandard commented 1 week ago

Hi, everyone. Is anybody working on this issue? I can try to fix it if you don't mind.