angular / angular/components

Selection model in mat-tree with checkboxes example not matching displayed selection

Ouverte
#11,400 13 commentaires 10 réactions 0 personnes assignées Voir sur GitHub
area: material/tree P4
Langage dominant
TypeScript
Étoiles
25k
Forks
6.8k
Merge moyen
1 j 8 h
PR mergées (30 j)
91

Description

#### Bug, feature request, or proposal:
Bug in example code

#### What is the expected behavior?
Selection model in example should be consistent with selected items.

#### What is the current behavior?
When you select a parent tree item it shows up in the selection model, however if you select all of the items under a tree individually, the parent item will show as checked, but will not appear in the selection model.

#### What are the steps to reproduce?
see checkboxes example from documentation: https://material.angular.io/components/tree/examples or stackblitz clone: https://stackblitz.com/angular/nkmjydodvnp?file=app%2Ftree-checklist-example.html
to reproduce, click checkbox for a parent tree and view selectionmodel.selected
uncheck parent tree then check all child items, selection model will be different and not match display.

#### What is the use-case or motivation for changing an existing behavior?
To provide good examples with predictable behavior.

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
angular material 6.02

#### Is there anything else we should know?
easily fixed by a small change to decendantsAllSelected method. see working fix:
https://stackblitz.com/angular/nkmjydodvnp?file=app%2Ftree-checklist-example.ts
code:
```typescript
descendantsAllSelected(node: TodoItemFlatNode): boolean {
const descendants = this.treeControl.getDescendants(node);
let allselected = descendants.every(child => this.checklistSelection.isSelected(child));
if (allselected)
this.checklistSelection.select(node);
else
this.checklistSelection.deselect(node);
return allselected;
}
```

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par l’exemple mat-tree checkboxes et son fichier app/tree-checklist-example.ts, en particulier descendantsAllSelected. Reproduisez l’incohérence en sélectionnant un parent, puis tous ses enfants, et comparez les cases à cocher affichées avec checklistSelection.selected. Le travail est terminé lorsque l’exemple maintient ces deux représentations cohérentes ; vérifiez le comportement dans l’exemple de la documentation.

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é
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
55/100

Recevez les nouvelles issues par e-mail

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