angular / angular/components

Dynamic autocomplete options - "reboot"

Ouverte
#15,697 2 commentaires 4 réactions 0 personnes assignées Voir sur GitHub
area: material/autocomplete feature P4
Langage dominant
TypeScript
Étoiles
25k
Forks
6.8k
Merge moyen
1 j 8 h
PR mergées (30 j)
91

Description

#### Please describe the feature you would like to request.

Currently working with the autocompleter (or select) and using different templates which define and bubble up mat-optgroups is a challenging and manual process requiring understanding of the inner workings of the components and direct access of private fields.

https://stackblitz.com/edit/dynamic-autocomplete

In addition, when there are no "real" top-level options, a shim disabled option must be inserted and then disguised (or else very undesirable workarounds that don't work well with ngrx state-driven option lists must be undertaken). Otherwise, the autocomplete will not open, and reindexing of select handlers for the dynamic options will fail, so that the list either does not appear initially or cannot be navigated/selected from.

As this is a common use case for autocompleters with behavior driven by another selection (e.g.), and we do not want to access internals, we would like to propose a "reboot" method on the autocomplete (and select) whereby a group of MatOptions can be provided and Material will handle getting things into the correct state.

e.g.
```
...
this.autocomplete.setOptions(options);
...
```

#### What is the use-case or motivation for this proposal?

We have encountered multiple scenarios that were best handled by choosing between multiple optgroup-producing templates. For instance, another select may cause the user to choose a "Type" which then should drive our autocomplete to choose between a very complicated and a very simple template.

Currently, realizing this behavior (without putting all of it in one god controller) is unsafe as we must access class internals, and requires specific and fragile knowledge and patterns.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par reproduire les scénarios d’options et d’optgroups dynamiques dans le StackBlitz lié, puis consultez les APIs des composants autocomplete et select concernant la gestion des options. Déterminez comment une API publique reboot ou setOptions pourrait prendre en charge les MatOptions dynamiques sans accès aux champs privés, et vérifiez que l’autocomplete s’ouvre et que les options restent navigables et sélectionnables.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
angular, typescript
Domaine
frontend
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

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