@@ -6,9 +6,10 @@ Start by adding a regular `matInput` to your template. Let's assume you're using
66directive from ` ReactiveFormsModule ` to track the value of the input.
77
88> Note: It is possible to use template-driven forms instead, if you prefer. We use reactive forms
9- in this example because it makes subscribing to changes in the input's value easy. For this example, be sure to
10- import ` ReactiveFormsModule ` from ` @angular/forms ` into your ` NgModule ` . If you are unfamiliar with using reactive
11- forms, you can read more about the subject in the [ Angular documentation] ( https://angular.io/guide/reactive-forms ) .
9+ in this example because it makes subscribing to changes in the input's value easy. For this
10+ example, be sure to import ` ReactiveFormsModule ` from ` @angular/forms ` into your ` NgModule ` .
11+ If you are unfamiliar with using reactive forms, you can read more about the subject in the
12+ [ Angular documentation] ( https://angular.io/guide/reactive-forms ) .
1213
1314* my-comp.html*
1415``` html
@@ -41,9 +42,7 @@ to the input's `matAutocomplete` property.
4142</mat-form-field >
4243
4344<mat-autocomplete #auto =" matAutocomplete" >
44- <mat-option *ngFor =" let option of options" [value] =" option" >
45- {{ option }}
46- </mat-option >
45+ <mat-option *ngFor =" let option of options" [value] =" option" >{{option}}</mat-option >
4746</mat-autocomplete >
4847```
4948
@@ -61,8 +60,8 @@ option's first letter. We already have access to the built-in `valueChanges` Obs
6160them through this filter. The resulting Observable, ` filteredOptions ` , can be added to the
6261template in place of the ` options ` property using the ` async ` pipe.
6362
64- Below we are also priming our value change stream with an empty string so that the options are filtered by
65- that value on init (before there are any value changes).
63+ Below we are also priming our value change stream with an empty string so that the options are
64+ filtered by that value on init (before there are any value changes).
6665
6766\* For optimal accessibility, you may want to consider adding text guidance on the page to explain
6867filter criteria. This is especially helpful for screenreader users if you're using a non-standard
@@ -91,6 +90,27 @@ injection token.
9190
9291<!-- example(autocomplete-auto-active-first-option) -->
9392
93+ ### Attaching the autocomplete panel to a different element
94+
95+ By default the autocomplete panel will be attached to your input element, however in some cases you
96+ may want it to attach to a different container element. You can change the element that the
97+ autocomplete is attached to using the ` matAutocompleteOrigin ` directive together with the
98+ ` matAutocompleteConnectedTo ` input:
99+
100+ ``` html
101+ <div class =" custom-wrapper-example" matAutocompleteOrigin #origin =" matAutocompleteOrigin" >
102+ <input
103+ matInput
104+ [formControl] =" myControl"
105+ [matAutocomplete] =" auto"
106+ [matAutocompleteConnectedTo] =" origin" >
107+ </div >
108+
109+ <mat-autocomplete #auto =" matAutocomplete" >
110+ <mat-option *ngFor =" let option of options" [value] =" option" >{{option}}</mat-option >
111+ </mat-autocomplete >
112+ ```
113+
94114### Keyboard interaction
95115- <kbd >DOWN_ARROW</kbd >: Next option becomes active.
96116- <kbd >UP_ARROW</kbd >: Previous option becomes active.
@@ -105,7 +125,7 @@ injection token.
105125<mat-autocomplete #auto =" matAutocomplete" >
106126 <mat-optgroup *ngFor =" let group of filteredGroups | async" [label] =" group.name" >
107127 <mat-option *ngFor =" let option of group.options" [value] =" option" >
108- {{ option.name }}
128+ {{option.name}}
109129 </mat-option >
110130 </mat-optgroup >
111131</mat-autocomplete >
@@ -115,5 +135,5 @@ injection token.
115135The input for an autocomplete without text or labels should be given a meaningful label via
116136` aria-label ` or ` aria-labelledby ` .
117137
118- The autocomplete trigger is given ` role="combobox" ` . The trigger sets ` aria-owns ` to the autocomplete's
119- id, and sets ` aria-activedescendant ` to the active option's id.
138+ The autocomplete trigger is given ` role="combobox" ` . The trigger sets ` aria-owns ` to the
139+ autocomplete's id, and sets ` aria-activedescendant ` to the active option's id.
0 commit comments