Skip to content

Commit 3e30763

Browse files
jelbourncrisbeto
authored andcommitted
wip
1 parent 3c6f7a2 commit 3e30763

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

src/cdk/overlay/overlay-ref.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {PortalHost, Portal} from '@angular/cdk/portal';
1111
import {OverlayConfig} from './overlay-config';
1212
import {Observable} from 'rxjs/Observable';
1313
import {Subject} from 'rxjs/Subject';
14+
import {first} from 'rxjs/operator/first';
1415

1516

1617
/**
@@ -61,6 +62,13 @@ export class OverlayRef implements PortalHost {
6162
this._config.scrollStrategy.enable();
6263
}
6364

65+
// Update the position once the zone is stable so that the overlay will be fully rendered
66+
// before attempting to position it, as the position may depend on the size of the rendered
67+
// content.
68+
first.call(this._ngZone.onStable).subscribe(() => {
69+
this.updatePosition();
70+
});
71+
6472
// Enable pointer events for the overlay pane element.
6573
this._togglePointerEvents(true);
6674

src/cdk/overlay/overlay.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {async, ComponentFixture, inject, TestBed} from '@angular/core/testing';
1+
import {async, fakeAsync, tick, ComponentFixture, inject, TestBed} from '@angular/core/testing';
22
import {Component, NgModule, ViewChild, ViewContainerRef} from '@angular/core';
33
import {
44
ComponentPortal,
@@ -107,7 +107,7 @@ describe('Overlay', () => {
107107
expect(overlayContainerElement.textContent).toBe('');
108108
});
109109

110-
it('should ensure that the most-recently-attached overlay is on top', () => {
110+
it('should ensure that the most-recently-attached overlay is on top', (() => {
111111
let pizzaOverlayRef = overlay.create();
112112
let cakeOverlayRef = overlay.create();
113113

@@ -130,7 +130,7 @@ describe('Overlay', () => {
130130
.toBeTruthy('Expected pizza to still be on the bottom.');
131131
expect(cakeOverlayRef.overlayElement.nextSibling)
132132
.toBeFalsy('Expected cake to still be on top.');
133-
});
133+
}));
134134

135135
it('should set the direction', () => {
136136
const config = new OverlayConfig({direction: 'rtl'});
@@ -226,13 +226,15 @@ describe('Overlay', () => {
226226
config = new OverlayConfig();
227227
});
228228

229-
it('should apply the positioning strategy', () => {
229+
it('should apply the positioning strategy', fakeAsync(() => {
230230
config.positionStrategy = new FakePositionStrategy();
231231

232232
overlay.create(config).attach(componentPortal);
233+
viewContainerFixture.detectChanges();
234+
tick();
233235

234236
expect(overlayContainerElement.querySelectorAll('.fake-positioned').length).toBe(1);
235-
});
237+
}));
236238
});
237239

238240
describe('size', () => {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ export class ConnectedPositionStrategy implements PositionStrategy {
147147
* allows one to re-align the panel without changing the orientation of the panel.
148148
*/
149149
recalculateLastPosition(): void {
150+
// If the overlay had never been positioned before, do nothing.
151+
if (!this._lastConnectedPosition) {
152+
return;
153+
}
154+
150155
const originRect = this._origin.getBoundingClientRect();
151156
const overlayRect = this._pane.getBoundingClientRect();
152157
const viewportRect = this._viewportRuler.getViewportRect();

src/lib/dialog/dialog-container.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
ChangeDetectorRef,
1818
ViewChild,
1919
ViewEncapsulation,
20+
ChangeDetectionStrategy,
2021
} from '@angular/core';
2122
import {animate, AnimationEvent, state, style, transition, trigger} from '@angular/animations';
2223
import {DOCUMENT} from '@angular/platform-browser';
@@ -118,7 +119,13 @@ export class MatDialogContainer extends BasePortalHost {
118119
}
119120

120121
this._savePreviouslyFocusedElement();
121-
return this._portalHost.attachComponentPortal(portal);
122+
123+
const componentRef = this._portalHost.attachComponentPortal(portal);
124+
125+
// Ensure that the initial view change are picked up.
126+
componentRef.changeDetectorRef.markForCheck();
127+
128+
return componentRef;
122129
}
123130

124131
/**
@@ -131,7 +138,12 @@ export class MatDialogContainer extends BasePortalHost {
131138
}
132139

133140
this._savePreviouslyFocusedElement();
134-
return this._portalHost.attachTemplatePortal(portal);
141+
142+
const locals = this._portalHost.attachTemplatePortal(portal);
143+
144+
this._changeDetectorRef.markForCheck();
145+
146+
return locals;
135147
}
136148

137149
/** Moves the focus inside the focus trap. */

src/lib/menu/menu.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ describe('MatMenu', () => {
990990
.not.toContain('mat-elevation-z3', 'Expected no stacked elevation.');
991991
});
992992

993-
it('should close all of the menus when the root is closed programmatically', fakeAsync(() => {
993+
it('should close all of the menus when the root is closed programmatically', () => {
994994
compileTestComponent();
995995
instance.rootTrigger.openMenu();
996996
fixture.detectChanges();
@@ -1007,13 +1007,9 @@ describe('MatMenu', () => {
10071007

10081008
instance.rootTrigger.closeMenu();
10091009
fixture.detectChanges();
1010-
tick(500);
10111010

10121011
expect(overlay.querySelectorAll('.mat-menu-panel').length).toBe(0, 'Expected no open menus');
1013-
expect(instance.rootCloseCallback).toHaveBeenCalledTimes(1);
1014-
expect(instance.levelOneCloseCallback).toHaveBeenCalledTimes(1);
1015-
expect(instance.levelTwoCloseCallback).toHaveBeenCalledTimes(1);
1016-
}));
1012+
});
10171013

10181014
it('should toggle a nested menu when its trigger is added after init', fakeAsync(() => {
10191015
compileTestComponent();

0 commit comments

Comments
 (0)