angular / angular/components

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

Aperta
#11,400 13 commenti 10 reazioni 0 assegnatari Vedi su GitHub
area: material/tree P4
Lingua principale
TypeScript
Stelle
25k
Fork
6.8k
Merge medio
1g 8h
PR unite (30g)
91

Descrizione

#### 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;
}
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con l’esempio mat-tree checkboxes e il relativo file app/tree-checklist-example.ts, in particolare descendantsAllSelected. Riproduci la discrepanza selezionando un elemento padre e poi tutti i suoi elementi figli, quindi confronta le caselle visualizzate con checklistSelection.selected. Il lavoro è completato quando l’esempio mantiene coerenti queste due rappresentazioni; verifica il comportamento nell’esempio della documentazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
frontend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.