@@ -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
@@ -61,8 +62,8 @@ option's first letter. We already have access to the built-in `valueChanges` Obs
6162them through this filter. The resulting Observable, ` filteredOptions ` , can be added to the
6263template in place of the ` options ` property using the ` async ` pipe.
6364
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).
65+ Below we are also priming our value change stream with an empty string so that the options are
66+ filtered by that value on init (before there are any value changes).
6667
6768\* For optimal accessibility, you may want to consider adding text guidance on the page to explain
6869filter criteria. This is especially helpful for screenreader users if you're using a non-standard
@@ -91,6 +92,29 @@ injection token.
9192
9293<!-- example(autocomplete-auto-active-first-option) -->
9394
95+ ### Attaching the autocomplete panel to a different element
96+
97+ By default the autocomplete panel will be attached to your input element, however in some cases you
98+ may want it to attach to a different container element. You can change the element that the
99+ autocomplete is attached to using the ` matAutocompleteOrigin ` directive together with the
100+ ` matAutocompleteConnectedTo ` input:
101+
102+ ``` html
103+ <div class =" custom-wrapper-example" matAutocompleteOrigin #origin =" matAutocompleteOrigin" >
104+ <input
105+ matInput
106+ [formControl] =" myControl"
107+ [matAutocomplete] =" auto"
108+ [matAutocompleteConnectedTo] =" origin" >
109+ </div >
110+
111+ <mat-autocomplete #auto =" matAutocomplete" >
112+ <mat-option *ngFor =" let option of options" [value] =" option" >
113+ {{ option }}
114+ </mat-option >
115+ </mat-autocomplete >
116+ ```
117+
94118### Keyboard interaction
95119- <kbd >DOWN_ARROW</kbd >: Next option becomes active.
96120- <kbd >UP_ARROW</kbd >: Previous option becomes active.
@@ -115,5 +139,5 @@ injection token.
115139The input for an autocomplete without text or labels should be given a meaningful label via
116140` aria-label ` or ` aria-labelledby ` .
117141
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.
142+ The autocomplete trigger is given ` role="combobox" ` . The trigger sets ` aria-owns ` to the
143+ autocomplete's id, and sets ` aria-activedescendant ` to the active option's id.
0 commit comments