@@ -47,6 +47,7 @@ import {
4747 MatAutocompleteModule ,
4848 MatAutocompleteSelectedEvent ,
4949 MatAutocompleteTrigger ,
50+ MatAutocompleteOrigin ,
5051} from './index' ;
5152
5253
@@ -2218,6 +2219,34 @@ describe('MatAutocomplete', () => {
22182219 const fixture = createComponent ( AutocompleteWithDifferentOrigin ) ;
22192220
22202221 fixture . detectChanges ( ) ;
2222+ fixture . componentInstance . connectedTo = fixture . componentInstance . alternateOrigin ;
2223+ fixture . detectChanges ( ) ;
2224+ fixture . componentInstance . trigger . openPanel ( ) ;
2225+ fixture . detectChanges ( ) ;
2226+ zone . simulateZoneExit ( ) ;
2227+
2228+ const overlayRect =
2229+ overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ! . getBoundingClientRect ( ) ;
2230+ const originRect = fixture . nativeElement . querySelector ( '.origin' ) . getBoundingClientRect ( ) ;
2231+
2232+ expect ( Math . floor ( overlayRect . top ) ) . toBe ( Math . floor ( originRect . bottom ) ,
2233+ 'Expected autocomplete panel to align with the bottom of the new origin.' ) ;
2234+ } ) ;
2235+
2236+ it ( 'should be able to change the origin after the panel has been opened' , ( ) => {
2237+ const fixture = createComponent ( AutocompleteWithDifferentOrigin ) ;
2238+
2239+ fixture . detectChanges ( ) ;
2240+ fixture . componentInstance . trigger . openPanel ( ) ;
2241+ fixture . detectChanges ( ) ;
2242+ zone . simulateZoneExit ( ) ;
2243+
2244+ fixture . componentInstance . trigger . closePanel ( ) ;
2245+ fixture . detectChanges ( ) ;
2246+
2247+ fixture . componentInstance . connectedTo = fixture . componentInstance . alternateOrigin ;
2248+ fixture . detectChanges ( ) ;
2249+
22212250 fixture . componentInstance . trigger . openPanel ( ) ;
22222251 fixture . detectChanges ( ) ;
22232252 zone . simulateZoneExit ( ) ;
@@ -2603,7 +2632,7 @@ class AutocompleteWithNumberInputAndNgModel {
26032632 <input
26042633 matInput
26052634 [matAutocomplete]="auto"
2606- [matAutocompleteConnectedTo]="origin "
2635+ [matAutocompleteConnectedTo]="connectedTo "
26072636 [(ngModel)]="selectedValue">
26082637 </mat-form-field>
26092638 </div>
@@ -2623,8 +2652,10 @@ class AutocompleteWithNumberInputAndNgModel {
26232652} )
26242653class AutocompleteWithDifferentOrigin {
26252654 @ViewChild ( MatAutocompleteTrigger ) trigger : MatAutocompleteTrigger ;
2655+ @ViewChild ( MatAutocompleteOrigin ) alternateOrigin : MatAutocompleteOrigin ;
26262656 selectedValue : string ;
26272657 values = [ 'one' , 'two' , 'three' ] ;
2658+ connectedTo ?: MatAutocompleteOrigin ;
26282659}
26292660
26302661@Component ( {
0 commit comments