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-selection-list): Model change fired twice for the selection list with [multiple]="false" #22276

Closed
Vitaljok opened this issue Mar 18, 2021 · 1 comment · Fixed by #22376
Assignees
Labels
area: material/list P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@Vitaljok
Copy link

Vitaljok commented Mar 18, 2021

For the mat-selection-list with multiple selections disabled the model change event is fired twice.

StackBlitz to reproduce:

Steps to reproduce:

  1. Change the selection
  2. View result in the console: onChange is called twice.

Essential part of code:

<mat-selection-list [multiple]="false" [(ngModel)]="myValue" (ngModelChange)="onChange($event)">
...
</mat-selection-list>

An example is showing binding via [(ngModel)], but the same behavior is observed with reactive forms when valueChanges are fired twice.

Expected Behavior

Model change should be fired once similar as it works for lists with multiple selections allowed.

Actual Behavior

Model change is fired twice.

Environment

  • Angular: 11.2.5
  • CDK/Material: 11.2.4
  • Browser(s): Chrome 88.0.4324.150
  • Operating System (e.g. Windows, macOS, Ubuntu): Ubuntu

Edit: added essential part of code to the issue itself.

@Vitaljok Vitaljok added the needs triage This issue needs to be triaged by the team label Mar 18, 2021
@jelbourn jelbourn added area: material/list P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Mar 18, 2021
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 31, 2021
…single selection mode

Fixes that the MDC-based list dispatches its `ngModelChange` event multiple times when the value changes in single selection mode.

Fixes angular#22276.
@crisbeto crisbeto self-assigned this Mar 31, 2021
mmalerba pushed a commit that referenced this issue Apr 13, 2021
…single selection mode (#22376)

Fixes that the MDC-based list dispatches its `ngModelChange` event multiple times when the value changes in single selection mode.

Fixes #22276.
mmalerba pushed a commit that referenced this issue Apr 13, 2021
…single selection mode (#22376)

Fixes that the MDC-based list dispatches its `ngModelChange` event multiple times when the value changes in single selection mode.

Fixes #22276.

(cherry picked from commit 7702177)
@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 May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/list P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
3 participants