-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Closed
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/core
Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
When using compareWith, setSelection method may deselect comparable items.
Cause is usage of Set and has method
components/src/cdk/collections/selection-model.ts
Lines 94 to 98 in 7c8a796
| const newSelectedSet = new Set(values); | |
| values.forEach(value => this._markSelected(value)); | |
| oldValues | |
| .filter(value => !newSelectedSet.has(value)) | |
| .forEach(value => this._unmarkSelected(value)); |
This line
| const newSelectedSet = new Set(values); |
const newSelectedSet = new Set(values.map(value => this._getConcreteValue(value)));to use compareWith
Reproduction
StackBlitz link: https://stackblitz.com/edit/angular-jfhnli?file=src%2Fmain.ts
Steps to reproduce:
- Instanciate a SelectionModel of object and non trivial compareWith function
- call setSelection method to select one object o1, selectionModel.selection should be [o1]
- call setSelection again with a copy o2 of previous object (o2 must be comparable to o1 according compareWith, ie compareWith(o1,o2) is true)
Expected Behavior
SelectionModel selection should be one of the selected objects, either [o1] or [o2]
Actual Behavior
SelectionModel selection is empty
Environment
- Angular: 16
- CDK/Material: 16
- Browser(s): no browser needed
- Operating System (e.g. Windows, macOS, Ubuntu): Windows
sannies
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/core