angular / angular/components

Use of custom TrackByFunction in MatTree does not preserve expansion state when nodes change

Abierto
#15,872 8 comentarios 17 reacciones 0 asignados Ver en GitHub
area: material/tree G P2
Lenguaje dominante
TypeScript
Estrellas
25k
Forks
6.8k
Merge medio
1 d 8 h
PR fusionados (30 d)
91

Descripción

#### What is the expected behavior?

Use of trackBy should also ensure that the expansion state does not get lost when nodes are updated.

#### What is the current behavior?

Use of trackBy does not ensure that the expansion state does not get lost when nodes are updated. This is presumably since TreeControl uses an expansionModel which is a SelectionModel where the SelectionModel has no awareness of the TrackByFunction.

#### What are the steps to reproduce?

Relying upon the TreeControl expansionModel:
https://stackblitz.com/edit/angular-5wpr9o-kjnmsn?file=app%2Ftree-flat-overview-example.ts

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

all

#### Is there anything else we should know?

Trying to store expansion state in the nodes themselves as a workaround doesn't work (unless you transfer the state):
https://stackblitz.com/edit/angular-5wpr9o-ahptjs?file=app%2Ftree-flat-overview-example.ts

Having a custom expansionModel that is aware of the trackBy state works to preserve state, since the TreeControl's expansion-related methods apparently aren't actually used internally by the tree component:
https://stackblitz.com/edit/angular-5wpr9o-pbmk1g?file=app%2Ftree-flat-overview-example.ts

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza con las reproducciones vinculadas de StackBlitz, especialmente app/tree-flat-overview-example.ts, e inspecciona cómo interactúan MatTree, TreeControl, TrackByFunction y expansionModel. Reproduce la pérdida del estado de expansión cuando los nodos se actualizan con un trackBy personalizado. Se considera terminado cuando el estado de expansión se conserva después de esas actualizaciones.

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
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.