Skip to content

Commit 8df2c81

Browse files
emoralesb05tinayuangao
authored andcommitted
fix(overlay): dimension not updated after init (#8765)
1 parent e84b993 commit 8df2c81

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/cdk/overlay/overlay-directives.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ describe('Overlay directives', () => {
140140

141141
const pane = overlayContainerElement.children[0] as HTMLElement;
142142
expect(pane.style.width).toEqual('250px');
143+
144+
fixture.componentInstance.isOpen = false;
145+
fixture.detectChanges();
146+
147+
fixture.componentInstance.width = 500;
148+
fixture.componentInstance.isOpen = true;
149+
fixture.detectChanges();
150+
151+
expect(pane.style.width).toEqual('500px');
143152
});
144153

145154
it('should set the height', () => {
@@ -149,6 +158,15 @@ describe('Overlay directives', () => {
149158

150159
const pane = overlayContainerElement.children[0] as HTMLElement;
151160
expect(pane.style.height).toEqual('100vh');
161+
162+
fixture.componentInstance.isOpen = false;
163+
fixture.detectChanges();
164+
165+
fixture.componentInstance.height = '50vh';
166+
fixture.componentInstance.isOpen = true;
167+
fixture.detectChanges();
168+
169+
expect(pane.style.height).toEqual('50vh');
152170
});
153171

154172
it('should set the min width', () => {
@@ -158,6 +176,15 @@ describe('Overlay directives', () => {
158176

159177
const pane = overlayContainerElement.children[0] as HTMLElement;
160178
expect(pane.style.minWidth).toEqual('250px');
179+
180+
fixture.componentInstance.isOpen = false;
181+
fixture.detectChanges();
182+
183+
fixture.componentInstance.minWidth = 500;
184+
fixture.componentInstance.isOpen = true;
185+
fixture.detectChanges();
186+
187+
expect(pane.style.minWidth).toEqual('500px');
161188
});
162189

163190
it('should set the min height', () => {
@@ -167,6 +194,15 @@ describe('Overlay directives', () => {
167194

168195
const pane = overlayContainerElement.children[0] as HTMLElement;
169196
expect(pane.style.minHeight).toEqual('500px');
197+
198+
fixture.componentInstance.isOpen = false;
199+
fixture.detectChanges();
200+
201+
fixture.componentInstance.minHeight = '250px';
202+
fixture.componentInstance.isOpen = true;
203+
fixture.detectChanges();
204+
205+
expect(pane.style.minHeight).toEqual('250px');
170206
});
171207

172208
it('should create the backdrop if designated', () => {

src/cdk/overlay/overlay-directives.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,14 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
383383
this._detachOverlay();
384384
}
385385
});
386+
} else {
387+
// Update the overlay size, in case the directive's inputs have changed
388+
this._overlayRef.updateSize({
389+
width: this.width,
390+
minWidth: this.minWidth,
391+
height: this.height,
392+
minHeight: this.minHeight,
393+
});
386394
}
387395

388396
this._position.withDirection(this.dir);

0 commit comments

Comments
 (0)