angular / angular/components

bug(material/chips): MatChipSelectionChange not emitting on certain deselections

Open
#27,909 1 comment 0 reactions 0 assignees View on GitHub
area: material/chips P3
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

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

`selectionChange` output for `MatChipOption` is [stated to be](https://material.angular.io/components/chips/api#MatChipOption):
> Emitted when the chip is selected or **deselected**.

But this is not true for deselection. It appears the event is only emitted for deselection when **the chip in question** is manually selected/toggled by the user. When the `MatChipListbox` is **in single-select mode and a chip is currently selected**, selecting a different chip means the prior chip is deselected --> deselecting should mean emitting the `selectionChange` event, but it is not happening in this scenario.

See the below StackBlitz link.

### Reproduction

StackBlitz link: https://stackblitz.com/edit/firqg1
Steps to reproduce:

(First chip is initially selected)
1. Click on the Second chip.
2. First chip becomes deselected, but no `selectionChange` output event was emitted (in this case, the `MatChipSelectionChange` object should be logged to the console).

### Expected Behavior

`selectionChange` output for the First chip should have emitted.

### Actual Behavior

`selectionChange` output for the First chip does not emit.

### Environment

- Angular: 16
- CDK/Material: 16.2.7 (latest)
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): Windows

Contributor guide

Open the contributing guide

Research direction

Open the linked StackBlitz reproduction and inspect the MatChipOption and MatChipListbox selection behavior described in the issue. Verify the single-select deselection path when selecting the second chip; done means the first chip emits its MatChipSelectionChange event when it becomes deselected.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.