angular / angular/components

Dynamic autocomplete options - "reboot"

Offen
#15,697 2 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: material/autocomplete feature P4
Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
91

Beschreibung

#### 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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, die Szenarien für dynamische Optionen und Optgroups im verlinkten StackBlitz zu reproduzieren, und lies anschließend die APIs der Autocomplete- und Select-Komponenten rund um die Optionsverarbeitung. Ermittle, wie eine öffentliche reboot- oder setOptions-API dynamische MatOptions ohne Zugriff auf private Felder unterstützen könnte, und überprüfe, dass das Autocomplete geöffnet wird und die Optionen navigierbar und auswählbar bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
frontend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.