Skip to content

Commit 008212a

Browse files
authored
fix(material/autocomplete): autocomplete panel top is cut off in landscape mode (#28982)
* fix(material/autocomplete): autocomplete panel top is cut off in landscape mode Fixes a bug in the Angular Material Autocomplete component where the autocomplete panel listbox top is cut off by the device screen when being viewed in landscape mode. This is because the listbox max-height is greater than the distance between the top of the autocomplete input and the screen top. Fixes b/284148377 * fix(material/autocomplete): autocomplete panel top is cut off in landscape mode Fixes lint error from previous commit which fixes Angular Component's autocomplete panel top from being cut off when viewed in landscape mode. The previous max-height of the panel is more than the height of the panel from the top of the input when in the bottom half to the top of the device's screen. Fixes b/284148377 * fix(material/autocomplete): autocomplete panel top cut off in landscape mode Fixes a bug in the Angular Material Autocomplete component where the autocomplete panel listbox is cut off by the device screen when being viewed in landscape mode. This is because the CDK overlay does not adjust its size based on the screen constraints when triggered. Fixes b/284148377 * fix(material/autocomplete): autocomplete panel top cut off in mobile landscape mode Fixes a bug in the Angular Material Autocomplete component where the autocomplete panel top was being cut off by the screen in mobile landscape mode. Updates previous fix to target adjustments on HandsetLandscape only. Fixes b/284148377 * refactor(material/autocomplete): autocomplete panel top cut off in mobile landscape mode Removing unnecessary comments. Fixes: b/284148377 * refactor(material/autocomplete): Injects Breakpoint to fix breaking tests Fixes broken presubmit tests for Angular Component's Autocomplete constructor by injecting BreakpointObserver rather than adding to the constructor. Fixes b/247881646 * fix(material/autocomplete): update style.bottom value for broken test Fixes breaking Angular Component Autocomplete comoponent's autocomplete spec.ts so that the value falls within an acceptable range based on the new behavior of the autocomplete in landscape mode. Fixes b/284148377 * fix(material/autocomplete): panel top gets cut off in mobile landscape view Updates previous fix to unsubscribe from the _breakpointObserver on ngOnDestroy. Fixes b/284148377 * fix(material/autocomplete): autocomplete panel gets cut off in mobile landscape Updates fix to autocomplete panel which was getting cut off in mobile landscape by correctly assigning const isHandsetLandscape to the subscription result.matches value and thus if isHandsetLandscape is true then applying flexible dimensions, grow after open and with viewport margin to the panel on open. Fixes b/284148377 * fix(material/autocomplete): autocomplete panel top cut off in mobile landscape Fixes Angular Components autocomplete so that when the panel is open in mobile landscape that it does not cut off at the top and the panel resizes/adjusts according to the viewport. Updates the previous fix to avoid subscribing to handsetLandscapeSubscription as a side effect. Fixes b/284148377 * fix(material/autocomplete): resets autocomplete panel positionStrategy when not in mobile landscape Updates the previous fix which checks for Breakpoint.HandsetLandscape and applies flexibleDimensions withGrowAfterOpen and adds withViewportMargin and removes those values if Breakpoint.HandsetLandscape is false. Fixes b/284148377 * refactor(material/autocomplete): autocomplete panel cut off in mobile landscape Updates BreakpointObserver import after rebasing latest changes. Fixes b/284148377
1 parent 209af0f commit 008212a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {addAriaReferencedId, removeAriaReferencedId} from '@angular/cdk/a11y';
1010
import {Directionality} from '@angular/cdk/bidi';
1111
import {DOWN_ARROW, ENTER, ESCAPE, TAB, UP_ARROW, hasModifierKey} from '@angular/cdk/keycodes';
12+
import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout';
1213
import {
1314
ConnectedPosition,
1415
FlexibleConnectedPositionStrategy,
@@ -161,6 +162,10 @@ export class MatAutocompleteTrigger
161162
/** Subscription to viewport size changes. */
162163
private _viewportSubscription = Subscription.EMPTY;
163164

165+
/** Implements BreakpointObserver to be used to detect handset landscape */
166+
private _breakpointObserver = inject(BreakpointObserver);
167+
private _handsetLandscapeSubscription = Subscription.EMPTY;
168+
164169
/**
165170
* Whether the autocomplete can open the next time it is focused. Used to prevent a focused,
166171
* closed autocomplete from being reopened if the user switches to another browser tab and then
@@ -282,6 +287,7 @@ export class MatAutocompleteTrigger
282287
window.removeEventListener('blur', this._windowBlurHandler);
283288
}
284289

290+
this._handsetLandscapeSubscription.unsubscribe();
285291
this._viewportSubscription.unsubscribe();
286292
this._componentDestroyed = true;
287293
this._destroyPanel();
@@ -790,6 +796,26 @@ export class MatAutocompleteTrigger
790796
overlayRef.updateSize({width: this._getPanelWidth()});
791797
}
792798
});
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+
});
793819
} else {
794820
// Update the trigger, panel width and direction, in case anything has changed.
795821
this._positionStrategy.setOrigin(this._getConnectedElement());
@@ -881,6 +907,7 @@ export class MatAutocompleteTrigger
881907
}
882908

883909
private _getOverlayPosition(): PositionStrategy {
910+
// Set default Overlay Position
884911
const strategy = this._overlay
885912
.position()
886913
.flexibleConnectedTo(this._getConnectedElement())

src/material/autocomplete/autocomplete.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ describe('MDC-based MatAutocomplete', () => {
21832183
let inputReference = fixture.debugElement.query(By.css('.mdc-text-field'))!.nativeElement;
21842184

21852185
// Push the element down so it has a little bit of space, but not enough to render.
2186-
inputReference.style.bottom = '75px';
2186+
inputReference.style.bottom = '100px';
21872187
inputReference.style.position = 'fixed';
21882188

21892189
dispatchFakeEvent(inputEl, 'focusin');

0 commit comments

Comments
 (0)