@@ -140,6 +140,7 @@ export class MatAutocompleteTrigger
140
140
private _scrollStrategy : ( ) => ScrollStrategy ;
141
141
private _keydownSubscription : Subscription | null ;
142
142
private _outsideClickSubscription : Subscription | null ;
143
+ private _handsetLandscapeBreakpointSubscription : Subscription | null ;
143
144
144
145
/** Old value of the native input. Used to work around issues with the `input` event on IE. */
145
146
private _previousValue : string | number | null ;
@@ -283,6 +284,7 @@ export class MatAutocompleteTrigger
283
284
window . removeEventListener ( 'blur' , this . _windowBlurHandler ) ;
284
285
}
285
286
287
+ this . _handsetLandscapeBreakpointSubscription ?. unsubscribe ( ) ;
286
288
this . _viewportSubscription . unsubscribe ( ) ;
287
289
this . _componentDestroyed = true ;
288
290
this . _destroyPanel ( ) ;
@@ -891,12 +893,19 @@ export class MatAutocompleteTrigger
891
893
. withFlexibleDimensions ( false )
892
894
. withPush ( false ) ;
893
895
894
- // Check breakpoint if being viewed in HandsetLandscape
895
- const isHandsetLandscape = this . _breakpointObserver
896
- . observe ( Breakpoints . HandsetLandscape )
897
- . subscribe ( result => {
898
- return result . matches ;
899
- } ) ;
896
+ if ( ! this . _handsetLandscapeBreakpointSubscription ) {
897
+ // Subscribe to the breakpoint events stream to detect when screen is in
898
+ // handsetLandscape. Only subscribe if/when this panel is open.
899
+ // BreakpointObserver only returns screen size or isMatched/matches boolean.
900
+ this . _handsetLandscapeBreakpointSubscription = this . _breakpointObserver
901
+ . observe ( Breakpoints . HandsetLandscape )
902
+ . subscribe ( result => {
903
+ return result . matches ;
904
+ } ) ;
905
+ }
906
+
907
+ // Check breakpoint if being viewed in HandsetLandscape via subscription (if not null)
908
+ const isHandsetLandscape = this . _handsetLandscapeBreakpointSubscription ;
900
909
// Apply HandsetLandscape settings to prevent overlay cutoff in that breakpoint
901
910
// Fixes b/284148377
902
911
if ( isHandsetLandscape ) {
0 commit comments