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(MatSelectionList): MatSelectionListChange options should contain automatically deselected values #26466

Open mcalmus opened 1 year ago

mcalmus commented 1 year ago

Is this a regression?

The previous version in which this bug was not present was

No response

Description

When using a MatSelectionList with multiple select mode off, selecting an item deselects the previously-selected item. If listening to changes, the options property of MatSelectionListChange only has the newly-selected value, not the previously selected value. The documentation indicates it should contain "changed" items. The one that was deselected should therefore be included.

Reproduction

Steps to reproduce:

  1. https://stackblitz.com/edit/angular-wqdcyq?file=src%2Fapp%2Flist-single-selection-example.ts
  2. Select an option - change count increases by one
  3. Select a different option - change count (and log) only shows one item rather than two

Expected Behavior

Change count after selecting a new item should increase by 2.

Actual Behavior

Change count only increases by one

Environment

mmalerba commented 1 year ago

Can you give more info about the use case you have in mind for this? I'm not sure this really makes sense for single selection, as selecting an item always implies all other options are unselected.

mcalmus commented 1 year ago

I would like to use a single change method for several components to audit changes. Once the change has fired there is no way to get the previous value.