Skip to content

Commit e48e6c7

Browse files
committed
wip
1 parent 9904e56 commit e48e6c7

File tree

8 files changed

+42
-16
lines changed

8 files changed

+42
-16
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cdk/overlay/overlay-ref.ts

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

1516

1617
/**
@@ -53,9 +54,15 @@ export class OverlayRef implements PortalHost {
5354
this._updateStackingOrder();
5455
this.updateSize();
5556
this.updateDirection();
56-
this.updatePosition();
5757
this._state.scrollStrategy.enable();
5858

59+
// Update the position once the zone is stable so that the overlay will be fully rendered
60+
// before attempting to position it, as the position may depend on the size of the rendered
61+
// content.
62+
first.call(this._ngZone.onStable).subscribe(() => {
63+
this.updatePosition();
64+
});
65+
5966
// Enable pointer events for the overlay pane element.
6067
this._togglePointerEvents(true);
6168

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 state = new OverlayState();
@@ -230,13 +230,15 @@ describe('Overlay', () => {
230230
state = new OverlayState();
231231
});
232232

233-
it('should apply the positioning strategy', () => {
233+
it('should apply the positioning strategy', fakeAsync(() => {
234234
state.positionStrategy = new FakePositionStrategy();
235235

236236
overlay.create(state).attach(componentPortal);
237+
viewContainerFixture.detectChanges();
238+
tick();
237239

238240
expect(overlayContainerElement.querySelectorAll('.fake-positioned').length).toBe(1);
239-
});
241+
}));
240242
});
241243

242244
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/autocomplete/autocomplete.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {Observable} from 'rxjs/Observable';
3030
import {Subject} from 'rxjs/Subject';
3131

3232

33-
describe('MdAutocomplete', () => {
33+
fdescribe('MdAutocomplete', () => {
3434
let overlayContainerElement: HTMLElement;
3535
let dir: Direction;
3636
let scrolledSubject = new Subject();

src/lib/dialog/dialog-container.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ChangeDetectorRef,
1919
ViewChild,
2020
ViewEncapsulation,
21+
ChangeDetectionStrategy,
2122
} from '@angular/core';
2223
import {animate, AnimationEvent, state, style, transition, trigger} from '@angular/animations';
2324
import {DOCUMENT} from '@angular/platform-browser';
@@ -51,6 +52,7 @@ export function throwMdDialogContentAlreadyAttachedError() {
5152
templateUrl: 'dialog-container.html',
5253
styleUrls: ['dialog.css'],
5354
encapsulation: ViewEncapsulation.None,
55+
changeDetection: ChangeDetectionStrategy.OnPush,
5456
animations: [
5557
trigger('slideDialog', [
5658
// Note: The `enter` animation doesn't transition to something like `translate3d(0, 0, 0)
@@ -118,7 +120,13 @@ export class MdDialogContainer extends BasePortalHost {
118120
}
119121

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

124132
/**
@@ -131,7 +139,12 @@ export class MdDialogContainer extends BasePortalHost {
131139
}
132140

133141
this._savePreviouslyFocusedElement();
134-
return this._portalHost.attachTemplatePortal(portal);
142+
143+
const locals = this._portalHost.attachTemplatePortal(portal);
144+
145+
this._changeDetectorRef.markForCheck();
146+
147+
return locals;
135148
}
136149

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

src/lib/menu/menu.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
} from '@angular/cdk/testing';
3333

3434

35-
describe('MdMenu', () => {
35+
fdescribe('MdMenu', () => {
3636
let overlayContainerElement: HTMLElement;
3737
let dir: Direction;
3838

@@ -974,7 +974,7 @@ describe('MdMenu', () => {
974974
.not.toContain('mat-elevation-z3', 'Expected no stacked elevation.');
975975
});
976976

977-
it('should close all of the menus when the root is closed programmatically', fakeAsync(() => {
977+
it('should close all of the menus when the root is closed programmatically', () => {
978978
compileTestComponent();
979979
instance.rootTrigger.openMenu();
980980
fixture.detectChanges();
@@ -991,10 +991,9 @@ describe('MdMenu', () => {
991991

992992
instance.rootTrigger.closeMenu();
993993
fixture.detectChanges();
994-
tick(500);
995994

996995
expect(overlay.querySelectorAll('.mat-menu-panel').length).toBe(0, 'Expected no open menus');
997-
}));
996+
});
998997

999998

1000999
});

src/lib/select/select.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
import {extendObject} from '../core/util/object-extend';
4242

4343

44-
describe('MdSelect', () => {
44+
fdescribe('MdSelect', () => {
4545
let overlayContainerElement: HTMLElement;
4646
let dir: {value: 'ltr'|'rtl'};
4747
let scrolledSubject = new Subject();

0 commit comments

Comments
 (0)