angular / components

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

feat(slide-toggle): prevent value change #28876

Open slavafomin opened 5 months ago

slavafomin commented 5 months ago

Feature Description

Hello! I'm using the slide-toggle component and I want to control when and how it's value changes. Just like controlled components in React. However, I can't find a way to do so.

When I pass a signal (not a model) to the component via [checked]="isChecked()" the value of the component continues to change once a user clicks on it (totally ignoring the fact that the symbol is not changed). This looks like a bug to me, or at least something very counter-intuitive.

Then I've tried to hook into the (change) event to manually call preventDefault() on it when the value changes, but the event object provided to the event handler doesn't have such method.

Calling preventDefault() from toggle/click event handlers doesn't have any effect as well.

What can I do to take the component under control?

Thanks.

Use Case

No response

crisbeto commented 5 months ago

There's some precedent for this with the clickAction option in MatCheckbox already so we should be able to something similar here.

naaajii commented 1 week ago

there's disableToggleValue in MatSlideToggleDefaultOptions which might help.