angular / angular/components

bug(CHIPS): chip-listbox is setting formControl as undefined after unselection - inconsistency with .setValue(null)

Ouverte
#32,084 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
area: material/chips P3
Langage dominant
TypeScript
Étoiles
25k
Forks
6.8k
Merge moyen
1 j 8 h
PR mergées (30 j)
91

Description

### Description

### Inconsistent behaviour between chip unselection vs. unselecting the chip by setting null value as formControl

When I want to programatically unselect a chip within a formGroup I can not setValue(undefined) only setValue(null).
I find that the behaviour is inconsistent and I understand why the initial value is undefined in case nothing was put onto the component. But after unselection I think it would be more rational to have it set up as null. Or preferably having null always as a default value within formGroup.

- I find this behaviour inconsistent and in case that I need to programatically unselect chipbox, then I need to map the final undefined value to null to have it correctly set in my project

Image

### Reproduction

[StackBlitz link: ](https://stackblitz.com/edit/components-issue-starter-wrxvkjqq?file=src%2Fmain.ts)
Steps to reproduce:
1. Select one of the three chips, for example 'Large'
2. Click on the button set as null
3. This works as expected, and the chips has value null.
4. Try to click on Large again
5. Unselect the selection by clicking on 'Large' again

You receive undefined

Image

Image

### Expected Behavior

Expected behaviour is to have either always undefined or null, or be able to set undefined programatically.
But preferably null over undefined

### Actual Behavior

Inconsistent behaviour between `myControl.setValue(null) ` - which is unselecting chip from the component
And the actual clicking on the selected chip which it makes unselected but automatically set value as undefined

### Environment

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

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par la reproduction StackBlitz liée et comparez les valeurs du contrôle de formulaire de chip-listbox après l'appel à setValue(null) et après avoir cliqué sur le chip sélectionné pour le désélectionner. C'est terminé lorsque le composant utilise systématiquement la valeur null ou undefined convenue dans les deux parcours.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
angular, typescript
Domaine
frontend
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.