Skip to content

bug(selection-model): SelectionModel does not always respect the compareWith function #25878

Closed
@stijnvn

Description

@stijnvn

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

SelectionModel does not always respect the compareWith function.

The lines in SelectionModel where it goes wrong:

https://github.com/angular/components/blob/14.1.3/src/cdk/collections/selection-model.ts#L212
https://github.com/angular/components/blob/14.1.3/src/cdk/collections/selection-model.ts#L97

Reproduction

https://stackblitz.com/edit/components-issue-8zah2s?file=src/app/example-component.ts

Steps to reproduce:

  1. Set up a selection model with multiple selection and compareWith function.
  2. Select an item.
  3. Try to deselect the item but pass a copy of the original item.

Expected Behavior

The item is deselected because it is equal to the original item according to the compareWith function.

Actual Behavior

The item is not deselected because the current implementation uses Set.delete to remove the item.

Environment

  • Angular: 14.1.3
  • CDK/Material: 14.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/collections

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions