Selection model in mat-tree with checkboxes example not matching displayed selection
- Lenguaje dominante
- TypeScript
- Estrellas
- 25k
- Forks
- 6.8k
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 91
Descripción
#### 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;
}
```
Guía de contribución
Línea de trabajo
Comienza con el mat-tree checkboxes example y su archivo app/tree-checklist-example.ts, especialmente con descendantsAllSelected. Reproduce la discrepancia seleccionando un elemento padre y después todos sus elementos hijos, y compara las casillas mostradas con checklistSelection.selected. La tarea está terminada cuando el ejemplo mantiene coherentes esas dos representaciones; verifica el comportamiento en el ejemplo de la documentación.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- angular, typescript
- Área
- frontend
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 55/100