Skip to content

Commit 5587f44

Browse files
author
emoralesb05
committed
fix(overlay): dimension not updated after init
1 parent 537b8b5 commit 5587f44

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

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

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

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

146155
it('should set the height', () => {
@@ -150,6 +159,15 @@ describe('Overlay directives', () => {
150159

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

155173
it('should set the min width', () => {
@@ -159,6 +177,15 @@ describe('Overlay directives', () => {
159177

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

164191
it('should set the min height', () => {
@@ -168,6 +195,15 @@ describe('Overlay directives', () => {
168195

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

173209
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
@@ -336,6 +336,14 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
336336
private _attachOverlay() {
337337
if (!this._overlayRef) {
338338
this._createOverlay();
339+
} else {
340+
// Update the overlay size, in case the directive's inputs have changed
341+
this._overlayRef.updateSize({
342+
width: this.width,
343+
minWidth: this.minWidth,
344+
height: this.height,
345+
minHeight: this.minHeight,
346+
});
339347
}
340348

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

src/lib/select/select.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,33 @@ describe('MatSelect', () => {
613613
expect(() => fixture.componentInstance.select.open()).not.toThrow();
614614
});
615615

616+
it('should set the width of the overlay based on the trigger and resize', fakeAsync(() => {
617+
trigger.style.width = '200px';
618+
fixture.detectChanges();
619+
fixture.whenStable().then(() => {
620+
trigger.click();
621+
fixture.detectChanges();
622+
const pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
623+
expect(pane.style.minWidth).toBe('200px',
624+
'Expected pane minWidth to be 200px initially');
625+
626+
const backdrop =
627+
overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
628+
backdrop.click();
629+
fixture.detectChanges();
630+
flush();
631+
632+
trigger.style.width = '400px';
633+
fixture.detectChanges();
634+
fixture.whenStable().then(() => {
635+
trigger.click();
636+
fixture.detectChanges();
637+
expect(pane.style.minWidth).toBe('400px',
638+
'Expected pane minWidth to be 400px after resize');
639+
});
640+
});
641+
}));
642+
616643
it('should open the panel when trigger is clicked', fakeAsync(() => {
617644
trigger.click();
618645
fixture.detectChanges();

0 commit comments

Comments
 (0)