Closed
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
This line could be replaced by
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