|
9 | 9 | import {addAriaReferencedId, removeAriaReferencedId} from '@angular/cdk/a11y';
|
10 | 10 | import {Directionality} from '@angular/cdk/bidi';
|
11 | 11 | import {DOWN_ARROW, ENTER, ESCAPE, TAB, UP_ARROW, hasModifierKey} from '@angular/cdk/keycodes';
|
| 12 | +import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout'; |
12 | 13 | import {
|
13 | 14 | ConnectedPosition,
|
14 | 15 | FlexibleConnectedPositionStrategy,
|
@@ -161,6 +162,10 @@ export class MatAutocompleteTrigger
|
161 | 162 | /** Subscription to viewport size changes. */
|
162 | 163 | private _viewportSubscription = Subscription.EMPTY;
|
163 | 164 |
|
| 165 | + /** Implements BreakpointObserver to be used to detect handset landscape */ |
| 166 | + private _breakpointObserver = inject(BreakpointObserver); |
| 167 | + private _handsetLandscapeSubscription = Subscription.EMPTY; |
| 168 | + |
164 | 169 | /**
|
165 | 170 | * Whether the autocomplete can open the next time it is focused. Used to prevent a focused,
|
166 | 171 | * closed autocomplete from being reopened if the user switches to another browser tab and then
|
@@ -282,6 +287,7 @@ export class MatAutocompleteTrigger
|
282 | 287 | window.removeEventListener('blur', this._windowBlurHandler);
|
283 | 288 | }
|
284 | 289 |
|
| 290 | + this._handsetLandscapeSubscription.unsubscribe(); |
285 | 291 | this._viewportSubscription.unsubscribe();
|
286 | 292 | this._componentDestroyed = true;
|
287 | 293 | this._destroyPanel();
|
@@ -790,6 +796,26 @@ export class MatAutocompleteTrigger
|
790 | 796 | overlayRef.updateSize({width: this._getPanelWidth()});
|
791 | 797 | }
|
792 | 798 | });
|
| 799 | + // Subscribe to the breakpoint events stream to detect when screen is in |
| 800 | + // handsetLandscape. |
| 801 | + this._handsetLandscapeSubscription = this._breakpointObserver |
| 802 | + .observe(Breakpoints.HandsetLandscape) |
| 803 | + .subscribe(result => { |
| 804 | + const isHandsetLandscape = result.matches; |
| 805 | + // Check if result.matches Breakpoints.HandsetLandscape. Apply HandsetLandscape |
| 806 | + // settings to prevent overlay cutoff in that breakpoint. Fixes b/284148377 |
| 807 | + if (isHandsetLandscape) { |
| 808 | + this._positionStrategy |
| 809 | + .withFlexibleDimensions(true) |
| 810 | + .withGrowAfterOpen(true) |
| 811 | + .withViewportMargin(8); |
| 812 | + } else { |
| 813 | + this._positionStrategy |
| 814 | + .withFlexibleDimensions(false) |
| 815 | + .withGrowAfterOpen(false) |
| 816 | + .withViewportMargin(0); |
| 817 | + } |
| 818 | + }); |
793 | 819 | } else {
|
794 | 820 | // Update the trigger, panel width and direction, in case anything has changed.
|
795 | 821 | this._positionStrategy.setOrigin(this._getConnectedElement());
|
@@ -881,6 +907,7 @@ export class MatAutocompleteTrigger
|
881 | 907 | }
|
882 | 908 |
|
883 | 909 | private _getOverlayPosition(): PositionStrategy {
|
| 910 | + // Set default Overlay Position |
884 | 911 | const strategy = this._overlay
|
885 | 912 | .position()
|
886 | 913 | .flexibleConnectedTo(this._getConnectedElement())
|
|
0 commit comments