@@ -139,7 +139,6 @@ export class MatAutocompleteTrigger
139
139
private _scrollStrategy : ( ) => ScrollStrategy ;
140
140
private _keydownSubscription : Subscription | null ;
141
141
private _outsideClickSubscription : Subscription | null ;
142
- private _handsetLandscapeBreakpointSubscription : Subscription | null ;
143
142
144
143
/** Old value of the native input. Used to work around issues with the `input` event on IE. */
145
144
private _previousValue : string | number | null ;
@@ -162,6 +161,10 @@ export class MatAutocompleteTrigger
162
161
/** Subscription to viewport size changes. */
163
162
private _viewportSubscription = Subscription . EMPTY ;
164
163
164
+ /** Implements BreakpointObserver to be used to detect handset landscape */
165
+ private _breakpointObserver = inject ( BreakpointObserver ) ;
166
+ private _handsetLandscapeSubscription = Subscription . EMPTY ;
167
+
165
168
/**
166
169
* Whether the autocomplete can open the next time it is focused. Used to prevent a focused,
167
170
* closed autocomplete from being reopened if the user switches to another browser tab and then
@@ -283,7 +286,7 @@ export class MatAutocompleteTrigger
283
286
window . removeEventListener ( 'blur' , this . _windowBlurHandler ) ;
284
287
}
285
288
286
- this . _handsetLandscapeBreakpointSubscription ? .unsubscribe ( ) ;
289
+ this . _handsetLandscapeSubscription . unsubscribe ( ) ;
287
290
this . _viewportSubscription . unsubscribe ( ) ;
288
291
this . _componentDestroyed = true ;
289
292
this . _destroyPanel ( ) ;
@@ -792,6 +795,23 @@ export class MatAutocompleteTrigger
792
795
overlayRef . updateSize ( { width : this . _getPanelWidth ( ) } ) ;
793
796
}
794
797
} ) ;
798
+ // Subscribe to the breakpoint events stream to detect when screen is in
799
+ // handsetLandscape.
800
+ this . _handsetLandscapeSubscription = this . _breakpointObserver
801
+ . observe ( Breakpoints . HandsetLandscape )
802
+ . subscribe ( result => {
803
+ const isHandsetLandscape = result . matches ;
804
+ // Check if result.matches Breakpoints.HandsetLandscape. Apply HandsetLandscape
805
+ // settings to prevent overlay cutoff in that breakpoint. Fixes b/284148377
806
+ if ( isHandsetLandscape ) {
807
+ this . _positionStrategy
808
+ . withFlexibleDimensions ( true )
809
+ . withGrowAfterOpen ( true )
810
+ . withViewportMargin ( 8 ) ;
811
+ } else {
812
+ this . _positionStrategy . withGrowAfterOpen ( false ) ;
813
+ }
814
+ } ) ;
795
815
} else {
796
816
// Update the trigger, panel width and direction, in case anything has changed.
797
817
this . _positionStrategy . setOrigin ( this . _getConnectedElement ( ) ) ;
@@ -882,9 +902,6 @@ export class MatAutocompleteTrigger
882
902
} ) ;
883
903
}
884
904
885
- /** Implements BreakpointObserver to be used to detect handset landscape */
886
- private _breakpointObserver = inject ( BreakpointObserver ) ;
887
-
888
905
private _getOverlayPosition ( ) : PositionStrategy {
889
906
// Set default Overlay Position
890
907
const strategy = this . _overlay
@@ -893,24 +910,6 @@ export class MatAutocompleteTrigger
893
910
. withFlexibleDimensions ( false )
894
911
. withPush ( false ) ;
895
912
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
- // Check breakpoint if being viewed in HandsetLandscape via subscription (if not null)
904
- const isHandsetLandscape = result . matches ;
905
- // Apply HandsetLandscape settings to prevent overlay cutoff in that breakpoint
906
- // Fixes b/284148377
907
- if ( isHandsetLandscape ) {
908
- strategy . withFlexibleDimensions ( true ) . withGrowAfterOpen ( true ) . withViewportMargin ( 8 ) ;
909
- }
910
- return ;
911
- } ) ;
912
- }
913
-
914
913
this . _setStrategyPositions ( strategy ) ;
915
914
this . _positionStrategy = strategy ;
916
915
return strategy ;
0 commit comments