Skip to content

Commit 84e2496

Browse files
jelbourncrisbeto
authored andcommitted
wip
1 parent f2cae6e commit 84e2496

File tree

7 files changed

+40
-13
lines changed

7 files changed

+40
-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 {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
/**
@@ -61,6 +62,13 @@ export class OverlayRef implements PortalHost {
6162
this._state.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 state = new OverlayState({direction: 'rtl'});
@@ -226,13 +226,15 @@ describe('Overlay', () => {
226226
state = new OverlayState();
227227
});
228228

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

232232
overlay.create(state).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/autocomplete/autocomplete.spec.ts

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

3434

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

src/lib/dialog/dialog-container.ts

Lines changed: 15 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';
@@ -50,6 +51,7 @@ export function throwMdDialogContentAlreadyAttachedError() {
5051
templateUrl: 'dialog-container.html',
5152
styleUrls: ['dialog.css'],
5253
encapsulation: ViewEncapsulation.None,
54+
changeDetection: ChangeDetectionStrategy.OnPush,
5355
animations: [
5456
trigger('slideDialog', [
5557
// Note: The `enter` animation doesn't transition to something like `translate3d(0, 0, 0)
@@ -117,7 +119,13 @@ export class MdDialogContainer extends BasePortalHost {
117119
}
118120

119121
this._savePreviouslyFocusedElement();
120-
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;
121129
}
122130

123131
/**
@@ -130,7 +138,12 @@ export class MdDialogContainer extends BasePortalHost {
130138
}
131139

132140
this._savePreviouslyFocusedElement();
133-
return this._portalHost.attachTemplatePortal(portal);
141+
142+
const locals = this._portalHost.attachTemplatePortal(portal);
143+
144+
this._changeDetectorRef.markForCheck();
145+
146+
return locals;
134147
}
135148

136149
/** 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
it('should toggle a nested menu when its trigger is added after init', fakeAsync(() => {
1000999
compileTestComponent();

src/lib/select/select.spec.ts

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

4444

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

0 commit comments

Comments
 (0)