@@ -47,6 +47,7 @@ import {
47
47
MatAutocompleteModule ,
48
48
MatAutocompleteSelectedEvent ,
49
49
MatAutocompleteTrigger ,
50
+ MatAutocompleteOrigin ,
50
51
} from './index' ;
51
52
52
53
@@ -2218,6 +2219,34 @@ describe('MatAutocomplete', () => {
2218
2219
const fixture = createComponent ( AutocompleteWithDifferentOrigin ) ;
2219
2220
2220
2221
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
+
2221
2250
fixture . componentInstance . trigger . openPanel ( ) ;
2222
2251
fixture . detectChanges ( ) ;
2223
2252
zone . simulateZoneExit ( ) ;
@@ -2603,7 +2632,7 @@ class AutocompleteWithNumberInputAndNgModel {
2603
2632
<input
2604
2633
matInput
2605
2634
[matAutocomplete]="auto"
2606
- [matAutocompleteConnectedTo]="origin "
2635
+ [matAutocompleteConnectedTo]="connectedTo "
2607
2636
[(ngModel)]="selectedValue">
2608
2637
</mat-form-field>
2609
2638
</div>
@@ -2623,8 +2652,10 @@ class AutocompleteWithNumberInputAndNgModel {
2623
2652
} )
2624
2653
class AutocompleteWithDifferentOrigin {
2625
2654
@ViewChild ( MatAutocompleteTrigger ) trigger : MatAutocompleteTrigger ;
2655
+ @ViewChild ( MatAutocompleteOrigin ) alternateOrigin : MatAutocompleteOrigin ;
2626
2656
selectedValue : string ;
2627
2657
values = [ 'one' , 'two' , 'three' ] ;
2658
+ connectedTo ?: MatAutocompleteOrigin ;
2628
2659
}
2629
2660
2630
2661
@Component ( {
0 commit comments