@@ -1497,6 +1497,50 @@ describe('MatAutocomplete', () => {
1497
1497
. toEqual ( Math . floor ( panelBottom ) , `Expected panel to stay aligned after filtering.` ) ;
1498
1498
} ) ) ;
1499
1499
1500
+ it ( 'should fall back to above position when requested if options are added while ' +
1501
+ 'the panel is open' , fakeAsync ( ( ) => {
1502
+ let fixture = createComponent ( AutocompleteWithOnPushDelay ) ;
1503
+ fixture . detectChanges ( ) ;
1504
+
1505
+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1506
+ let inputReference = fixture . debugElement . query ( By . css ( '.mat-form-field-flex' ) ) . nativeElement ;
1507
+
1508
+ // Push the element down so it has a little bit of space, but not enough to render.
1509
+ inputReference . style . bottom = '10px' ;
1510
+ inputReference . style . position = 'fixed' ;
1511
+
1512
+ // Focus the input to load the deferred options.
1513
+ dispatchFakeEvent ( inputEl , 'focusin' ) ;
1514
+ tick ( 1000 ) ;
1515
+
1516
+ fixture . detectChanges ( ) ;
1517
+ tick ( ) ;
1518
+
1519
+ const inputBottom = inputReference . getBoundingClientRect ( ) . bottom ;
1520
+ const panel = overlayContainerElement . querySelector ( '.mat-autocomplete-panel' ) ! ;
1521
+ const panelTop = panel . getBoundingClientRect ( ) . top ;
1522
+
1523
+ expect ( Math . floor ( inputBottom ) )
1524
+ . toEqual ( Math . floor ( panelTop ) ,
1525
+ `Expected panel top to be below input before repositioning.` ) ;
1526
+
1527
+ // Request a position update now that there are too many suggestions to fit in the viewport.
1528
+ fixture . componentInstance . trigger . updatePosition ( ) ;
1529
+
1530
+ const inputTop = inputReference . getBoundingClientRect ( ) . top ;
1531
+ const panelBottom = panel . getBoundingClientRect ( ) . bottom ;
1532
+
1533
+ expect ( Math . floor ( inputTop ) )
1534
+ . toEqual ( Math . floor ( panelBottom ) ,
1535
+ `Expected panel to fall back to above position after repositioning.` ) ;
1536
+ } ) ) ;
1537
+
1538
+ it ( 'should not throw if a panel reposition is requested while the panel is closed' , ( ) => {
1539
+ let fixture = createComponent ( SimpleAutocomplete ) ;
1540
+ fixture . detectChanges ( ) ;
1541
+
1542
+ expect ( ( ) => fixture . componentInstance . trigger . updatePosition ( ) ) . not . toThrow ( ) ;
1543
+ } ) ;
1500
1544
} ) ;
1501
1545
1502
1546
describe ( 'Option selection' , ( ) => {
@@ -2294,6 +2338,7 @@ class AutocompleteWithNumbers {
2294
2338
`
2295
2339
} )
2296
2340
class AutocompleteWithOnPushDelay implements OnInit {
2341
+ @ViewChild ( MatAutocompleteTrigger ) trigger : MatAutocompleteTrigger ;
2297
2342
options : string [ ] ;
2298
2343
2299
2344
ngOnInit ( ) {
0 commit comments