Skip to content

Commit

Permalink
fix(material/autocomplete): autocomplete panel top cut off in mobile …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
essjay05 committed May 9, 2024
1 parent 97dcaef commit 1acff7d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/material/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import {DOCUMENT} from '@angular/common';
import {Directionality} from '@angular/cdk/bidi';
import {DOWN_ARROW, ENTER, ESCAPE, TAB, UP_ARROW, hasModifierKey} from '@angular/cdk/keycodes';
import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout';
import {_getEventTarget} from '@angular/cdk/platform';
import {TemplatePortal} from '@angular/cdk/portal';
import {ViewportRuler} from '@angular/cdk/scrolling';
Expand Down Expand Up @@ -239,6 +240,8 @@ export class MatAutocompleteTrigger
private _viewContainerRef: ViewContainerRef,
private _zone: NgZone,
private _changeDetectorRef: ChangeDetectorRef,
/** Subscription to viewport orientation changes. */
private _breakpointObserver: BreakpointObserver,
@Inject(MAT_AUTOCOMPLETE_SCROLL_STRATEGY) scrollStrategy: any,
@Optional() private _dir: Directionality | null,
@Optional() @Inject(MAT_FORM_FIELD) @Host() private _formField: MatFormField | null,
Expand Down Expand Up @@ -880,14 +883,25 @@ export class MatAutocompleteTrigger
}

private _getOverlayPosition(): PositionStrategy {
// Set default Overlay Position
const strategy = this._overlay
.position()
.flexibleConnectedTo(this._getConnectedElement())
.withFlexibleDimensions(true)
.withGrowAfterOpen(true)
.withViewportMargin(8)
.withFlexibleDimensions(false)
.withPush(false);

// Check breakpoint if being viewed in HandsetLandscape
const isHandsetLandscape = this._breakpointObserver
.observe(Breakpoints.HandsetLandscape)
.subscribe(result => {
return result.matches;
});
// Apply HandsetLandscape settings to prevent overlay cutoff in that breakpoint
// Fixes b/284148377
if (isHandsetLandscape) {
strategy.withFlexibleDimensions(true).withGrowAfterOpen(true).withViewportMargin(8);
}

this._setStrategyPositions(strategy);
this._positionStrategy = strategy;
return strategy;
Expand Down

0 comments on commit 1acff7d

Please sign in to comment.