@@ -1478,6 +1478,54 @@ describe('MatAutocomplete', () => {
1478
1478
. toEqual ( Math . floor ( panelBottom ) , `Expected panel to stay aligned after filtering.` ) ;
1479
1479
} ) ) ;
1480
1480
1481
+ it ( 'should fall back to above position when requested if options are added while ' +
1482
+ 'the panel is open' , fakeAsync ( ( ) => {
1483
+ let fixture = createComponent ( AutocompleteWithOnPushDelay ) ;
1484
+ fixture . detectChanges ( ) ;
1485
+
1486
+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1487
+ let inputReference = fixture . debugElement . query ( By . css ( '.mat-form-field-flex' ) ) . nativeElement ;
1488
+
1489
+ // Push the element down so it has a little bit of space, but not enough to render.
1490
+ inputReference . style . bottom = '10px' ;
1491
+ inputReference . style . position = 'fixed' ;
1492
+
1493
+ // Focus the input to load the deferred options.
1494
+ dispatchFakeEvent ( inputEl , 'focusin' ) ;
1495
+ tick ( 1000 ) ;
1496
+
1497
+ fixture . detectChanges ( ) ;
1498
+ tick ( ) ;
1499
+
1500
+ Promise . resolve ( ) . then ( ( ) => {
1501
+ const inputBottom = inputReference . getBoundingClientRect ( ) . bottom ;
1502
+ const panel = overlayContainerElement . querySelector ( '.mat-autocomplete-panel' ) ! ;
1503
+ const panelTop = panel . getBoundingClientRect ( ) . top ;
1504
+
1505
+ expect ( Math . floor ( inputBottom ) )
1506
+ . toEqual ( Math . floor ( panelTop ) ,
1507
+ `Expected panel top to be below input before repositioning.` ) ;
1508
+
1509
+ // Request a position update now that there are too many suggestions to fit in the viewport.
1510
+ fixture . componentInstance . trigger . updatePosition ( ) ;
1511
+ fixture . detectChanges ( ) ;
1512
+ tick ( ) ;
1513
+
1514
+ const inputTop = inputReference . getBoundingClientRect ( ) . top ;
1515
+ const panelBottom = panel . getBoundingClientRect ( ) . bottom ;
1516
+
1517
+ expect ( Math . floor ( inputTop ) )
1518
+ . toEqual ( Math . floor ( panelBottom ) ,
1519
+ `Expected panel to fall back to above position after repositioning.` ) ;
1520
+ } ) ;
1521
+ } ) ) ;
1522
+
1523
+ it ( 'should not throw if a panel reposition is requested while the panel is closed' , ( ) => {
1524
+ let fixture = createComponent ( SimpleAutocomplete ) ;
1525
+ fixture . detectChanges ( ) ;
1526
+
1527
+ expect ( ( ) => fixture . componentInstance . trigger . updatePosition ( ) ) . not . toThrow ( ) ;
1528
+ } ) ;
1481
1529
} ) ;
1482
1530
1483
1531
describe ( 'Option selection' , ( ) => {
@@ -2198,6 +2246,7 @@ class AutocompleteWithNumbers {
2198
2246
`
2199
2247
} )
2200
2248
class AutocompleteWithOnPushDelay implements OnInit {
2249
+ @ViewChild ( MatAutocompleteTrigger ) trigger : MatAutocompleteTrigger ;
2201
2250
options : string [ ] ;
2202
2251
2203
2252
ngOnInit ( ) {
0 commit comments