Skip to content

Commit

Permalink
fix: reposition connected overlay on resize
Browse files Browse the repository at this point in the history
  • Loading branch information
crisbeto committed Sep 29, 2017
1 parent 88a082d commit 8d47cf4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/cdk/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ export class OverlayRef implements PortalHost {
// pointer events therefore. Depends on the position strategy and the applied pane boundaries.
this._togglePointerEvents(false);

if (this._state.positionStrategy && this._state.positionStrategy.detach) {
this._state.positionStrategy.detach();
}

if (this._state.scrollStrategy) {
this._state.scrollStrategy.disable();
}

let detachmentResult = this._portalHost.detach();
const detachmentResult = this._portalHost.detach();

// Only emit after everything is detached.
this._detachments.next();
Expand Down
16 changes: 15 additions & 1 deletion src/cdk/overlay/position/connected-position-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ScrollingVisibility,
} from './connected-position';
import {Subject} from 'rxjs/Subject';
import {Subscription} from 'rxjs/Subscription';
import {Observable} from 'rxjs/Observable';
import {Scrollable} from '@angular/cdk/scrolling';
import {isElementScrolledOutsideView, isElementClippedByScrolling} from './scroll-clip';
Expand All @@ -35,6 +36,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
/** The overlay to which this strategy is attached. */
private _overlayRef: OverlayRef;

/** Layout direction of the position strategy. */
private _dir = 'ltr';

/** The offset in pixels for the overlay connection point on the x-axis */
Expand All @@ -46,6 +48,9 @@ export class ConnectedPositionStrategy implements PositionStrategy {
/** The Scrollable containers used to check scrollable view properties on position change. */
private scrollables: Scrollable[] = [];

/** Subscription to viewport resize events. */
private _resizeSubscription = Subscription.EMPTY;

/** Whether the we're dealing with an RTL context */
get _isRtl() {
return this._dir === 'rtl';
Expand Down Expand Up @@ -88,10 +93,19 @@ export class ConnectedPositionStrategy implements PositionStrategy {
attach(overlayRef: OverlayRef): void {
this._overlayRef = overlayRef;
this._pane = overlayRef.overlayElement;
this._resizeSubscription.unsubscribe();
this._resizeSubscription = this._viewportRuler.change().subscribe(() => this.apply());
}

/** Performs any cleanup after the element is destroyed. */
dispose() { }
dispose() {
this._resizeSubscription.unsubscribe();
}

/** @docs-private */
detach() {
this._resizeSubscription.unsubscribe();
}

/**
* Updates the position of the overlay element, using whichever preferred position relative
Expand Down
3 changes: 3 additions & 0 deletions src/cdk/overlay/position/position-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export interface PositionStrategy {
/** Updates the position of the overlay element. */
apply(): void;

/** Called when the overlay is detached. */
detach?(): void;

/** Cleans up any DOM modifications made by the position strategy, if necessary. */
dispose(): void;
}
1 change: 0 additions & 1 deletion src/lib/tabs/tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
MATERIAL_COMPATIBILITY_MODE,
mixinDisableRipple,
} from '@angular/material/core';
import {fromEvent} from 'rxjs/observable/fromEvent';
import {merge} from 'rxjs/observable/merge';
import {of as observableOf} from 'rxjs/observable/of';
import {Subscription} from 'rxjs/Subscription';
Expand Down

0 comments on commit 8d47cf4

Please sign in to comment.