Use of custom TrackByFunction in MatTree does not preserve expansion state when nodes change
- Langage dominant
- TypeScript
- Étoiles
- 25k
- Forks
- 6.8k
- Merge moyen
- 1 j 8 h
- PR mergées (30 j)
- 91
Description
#### 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
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par les reproductions StackBlitz liées, en particulier app/tree-flat-overview-example.ts, et examinez comment MatTree, TreeControl, TrackByFunction et expansionModel interagissent. Reproduisez la perte de l’état d’expansion lorsque les nœuds sont mis à jour avec un trackBy personnalisé. Le travail est terminé lorsque l’état d’expansion reste préservé après ces mises à jour.
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é
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 38/100