Skip to content

Commit fd0f21f

Browse files
committed
fix: reposition connected overlay on resize
1 parent 0c00c76 commit fd0f21f

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/cdk/overlay/overlay-ref.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ export class OverlayRef implements PortalHost {
9595
// pointer events therefore. Depends on the position strategy and the applied pane boundaries.
9696
this._togglePointerEvents(false);
9797

98+
if (this._config.positionStrategy && this._config.positionStrategy.detach) {
99+
this._config.positionStrategy.detach();
100+
}
101+
98102
if (this._config.scrollStrategy) {
99103
this._config.scrollStrategy.disable();
100104
}
101105

102-
let detachmentResult = this._portalHost.detach();
106+
const detachmentResult = this._portalHost.detach();
103107

104108
// Only emit after everything is detached.
105109
this._detachments.next();

src/cdk/overlay/position/connected-position-strategy.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
ScrollingVisibility,
1818
} from './connected-position';
1919
import {Subject} from 'rxjs/Subject';
20+
import {Subscription} from 'rxjs/Subscription';
2021
import {Observable} from 'rxjs/Observable';
2122
import {Scrollable} from '@angular/cdk/scrolling';
2223
import {isElementScrolledOutsideView, isElementClippedByScrolling} from './scroll-clip';
@@ -35,6 +36,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
3536
/** The overlay to which this strategy is attached. */
3637
private _overlayRef: OverlayRef;
3738

39+
/** Layout direction of the position strategy. */
3840
private _dir = 'ltr';
3941

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

51+
/** Subscription to viewport resize events. */
52+
private _resizeSubscription = Subscription.EMPTY;
53+
4954
/** Whether the we're dealing with an RTL context */
5055
get _isRtl() {
5156
return this._dir === 'rtl';
@@ -88,10 +93,19 @@ export class ConnectedPositionStrategy implements PositionStrategy {
8893
attach(overlayRef: OverlayRef): void {
8994
this._overlayRef = overlayRef;
9095
this._pane = overlayRef.overlayElement;
96+
this._resizeSubscription.unsubscribe();
97+
this._resizeSubscription = this._viewportRuler.change().subscribe(() => this.apply());
9198
}
9299

93100
/** Performs any cleanup after the element is destroyed. */
94-
dispose() { }
101+
dispose() {
102+
this._resizeSubscription.unsubscribe();
103+
}
104+
105+
/** @docs-private */
106+
detach() {
107+
this._resizeSubscription.unsubscribe();
108+
}
95109

96110
/**
97111
* Updates the position of the overlay element, using whichever preferred position relative

src/cdk/overlay/position/position-strategy.ts

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export interface PositionStrategy {
1818
/** Updates the position of the overlay element. */
1919
apply(): void;
2020

21+
/** Called when the overlay is detached. */
22+
detach?(): void;
23+
2124
/** Cleans up any DOM modifications made by the position strategy, if necessary. */
2225
dispose(): void;
2326
}

src/lib/tabs/tab-header.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ import {
2727
ViewChild,
2828
ViewEncapsulation,
2929
} from '@angular/core';
30-
import {
31-
CanDisableRipple,
32-
MATERIAL_COMPATIBILITY_MODE,
33-
mixinDisableRipple,
34-
} from '@angular/material/core';
35-
import {fromEvent} from 'rxjs/observable/fromEvent';
30+
import {CanDisableRipple, mixinDisableRipple} from '@angular/material/core';
3631
import {merge} from 'rxjs/observable/merge';
3732
import {of as observableOf} from 'rxjs/observable/of';
3833
import {Subscription} from 'rxjs/Subscription';

0 commit comments

Comments
 (0)