bug(mat-slide-toggle): Use confirm dialog with slide toggle, if cancel the dialog, should not change the state
See original GitHub issueReproduction
Use StackBlitz to reproduce your issue: https://stackblitz.com/edit/angular-dchf74 Steps to reproduce:
- Click the slide toggle and select cancel the confirm dialog
- The state of the toggle still gets changed
After some research, (ngModelChange)="onHide()" will have the old value before toggling. Resetting value in the function body does NOT work. The implementation of slide-toggle is not something like slideToggleValue = !slideToggleValue?
event.stopPropogation() does NOT work also.
Wondering if there could be a workaround. Many thanks.
Expected Behavior
If click cancel, the state of the toggle should remain the old value.
Actual Behavior
If click cancel, the state of the toggle still gets changed
Environment
- Angular:
- CDK/Material:^9.0.0
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): macOS
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
mat-slide-toggle shouldn't change it's state when I click cancel ...
When I click cancel in that confirmation window, still the toggle changes to unchecked, which shouldn't happen. It should stay in the same...
Read more >Slide toggle | Angular Material
Used to set the aria-labelledby attribute on the underlying input element. @Input(). checked: boolean. Whether the slide-toggle element is checked or not.
Read more >mat-slide-toggle in Angular material - GeeksforGeeks
In order to install it, we need to have angular installed in our project, once you have it you can enter the below...
Read more >Angular Material Slide Toggle - ConcretePage.com
To use slide toggle, our Angular application must load HammerJS. Find the sample code to use <mat-slide-toggle> with formControl and change ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thank you Paul. This is exactly what I want.
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.