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(selection-model): SelectionModel does not always respect the compareWith function #25878

Closed
1 task
stijnvn opened this issue Oct 27, 2022 · 2 comments · Fixed by #26447
Closed
1 task
Labels
area: cdk/collections P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@stijnvn
Copy link
Contributor

stijnvn commented Oct 27, 2022

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
@stijnvn stijnvn added the needs triage This issue needs to be triaged by the team label Oct 27, 2022
stijnvn added a commit to stijnvn/components that referenced this issue Oct 27, 2022
@zarend zarend added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: cdk/collections and removed needs triage This issue needs to be triaged by the team labels Oct 27, 2022
@dollebrolle
Copy link

Suboptimal workaround until this use is solved: https://stackblitz.com/edit/components-issue-rkekpt?file=src%2Fapp%2Fexample-component.ts

FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 17, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 17, 2023
…compareWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 17, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 19, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 21, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 25, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 25, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 25, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 26, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 26, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 26, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 26, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
FrenchTechLead added a commit to FrenchTechLead/components that referenced this issue Jan 27, 2023
…areWith function

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes angular#25878
crisbeto pushed a commit that referenced this issue Jan 27, 2023
…areWith function (#26447)

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes #25878

(cherry picked from commit 50ec808)
crisbeto pushed a commit that referenced this issue Jan 27, 2023
…areWith function (#26447)

Fixed bug in SelectionModel where compareWith function was not consistently respected in deselect method.

Fixes #25878
@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 Feb 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/collections P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
3 participants