Skip to content

Commit 64a40e7

Browse files
author
emoralesb05
committed
fix(overlay): dimension not updated after init
2 parents 3352201 + 009c0a7 commit 64a40e7

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
@@ -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 = 500;
202+
fixture.componentInstance.isOpen = true;
203+
fixture.detectChanges();
204+
205+
expect(pane.style.minHeight).toEqual('500px');
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
@@ -385,6 +385,14 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
385385
this._detachOverlay();
386386
}
387387
});
388+
} else {
389+
// Update the overlay size, in case the directive's inputs have changed
390+
this._overlayRef.updateSize({
391+
width: this.width,
392+
minWidth: this.minWidth,
393+
height: this.height,
394+
minHeight: this.minHeight,
395+
});
388396
}
389397

390398
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
@@ -812,6 +812,33 @@ describe('MatSelect', () => {
812812
expect(() => fixture.componentInstance.select.open()).not.toThrow();
813813
});
814814

815+
it('should set the width of the overlay based on the trigger and resize', fakeAsync(() => {
816+
trigger.style.width = '200px';
817+
fixture.detectChanges();
818+
flush();
819+
820+
trigger.click();
821+
fixture.detectChanges();
822+
const pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
823+
expect(pane.style.minWidth).toBe('200px',
824+
'Expected pane minWidth to be 200px initially');
825+
826+
const backdrop =
827+
overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
828+
backdrop.click();
829+
fixture.detectChanges();
830+
flush();
831+
832+
trigger.style.width = '400px';
833+
fixture.detectChanges();
834+
flush();
835+
836+
trigger.click();
837+
fixture.detectChanges();
838+
expect(pane.style.minWidth).toBe('400px',
839+
'Expected pane minWidth to be 400px after resize');
840+
}));
841+
815842
it('should open the panel when trigger is clicked', fakeAsync(() => {
816843
trigger.click();
817844
fixture.detectChanges();

0 commit comments

Comments
 (0)