Skip to content

Commit a695574

Browse files
karammalerba
authored andcommitted
feat(overlay): support min width and min height (#2063)
1 parent 74772e1 commit a695574

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

src/lib/core/overlay/overlay-directives.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ describe('Overlay directives', () => {
8585
expect(pane.style.height).toEqual('100vh');
8686
});
8787

88+
it('should set the min width', () => {
89+
fixture.componentInstance.minWidth = 250;
90+
fixture.componentInstance.isOpen = true;
91+
fixture.detectChanges();
92+
93+
const pane = overlayContainerElement.children[0] as HTMLElement;
94+
expect(pane.style.minWidth).toEqual('250px');
95+
});
96+
97+
it('should set the min height', () => {
98+
fixture.componentInstance.minHeight = '500px';
99+
fixture.componentInstance.isOpen = true;
100+
fixture.detectChanges();
101+
102+
const pane = overlayContainerElement.children[0] as HTMLElement;
103+
expect(pane.style.minHeight).toEqual('500px');
104+
});
105+
88106
it('should create the backdrop if designated', () => {
89107
fixture.componentInstance.hasBackdrop = true;
90108
fixture.componentInstance.isOpen = true;
@@ -219,14 +237,16 @@ describe('Overlay directives', () => {
219237
[hasBackdrop]="hasBackdrop" backdropClass="md-test-class"
220238
(backdropClick)="backdropClicked=true" [offsetX]="offsetX" [offsetY]="offsetY"
221239
(positionChange)="positionChangeHandler($event)" (attach)="attachHandler()"
222-
(detach)="detachHandler()">
240+
(detach)="detachHandler()" [minWidth]="minWidth" [minHeight]="minHeight">
223241
<p>Menu content</p>
224242
</template>`,
225243
})
226244
class ConnectedOverlayDirectiveTest {
227245
isOpen = false;
228246
width: number | string;
229247
height: number | string;
248+
minWidth: number | string;
249+
minHeight: number | string;
230250
offsetX: number = 0;
231251
offsetY: number = 0;
232252
hasBackdrop: boolean;

src/lib/core/overlay/overlay-directives.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ export class ConnectedOverlayDirective implements OnDestroy {
106106
/** The height of the overlay panel. */
107107
@Input() height: number | string;
108108

109+
/** The min width of the overlay panel. */
110+
@Input() minWidth: number | string;
111+
112+
/** The min height of the overlay panel. */
113+
@Input() minHeight: number | string;
114+
109115
/** The custom class to be set on the backdrop element. */
110116
@Input() backdropClass: string;
111117

@@ -180,6 +186,14 @@ export class ConnectedOverlayDirective implements OnDestroy {
180186
overlayConfig.height = this.height;
181187
}
182188

189+
if (this.minWidth || this.minWidth === 0) {
190+
overlayConfig.minWidth = this.minWidth;
191+
}
192+
193+
if (this.minHeight || this.minHeight === 0) {
194+
overlayConfig.minHeight = this.minHeight;
195+
}
196+
183197
overlayConfig.hasBackdrop = this.hasBackdrop;
184198

185199
if (this.backdropClass) {

src/lib/core/overlay/overlay-ref.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ export class OverlayRef implements PortalHost {
8585
if (this._state.height || this._state.height === 0) {
8686
this._pane.style.height = formatCssUnit(this._state.height);
8787
}
88+
89+
if (this._state.minWidth || this._state.minWidth === 0) {
90+
this._pane.style.minWidth = formatCssUnit(this._state.minWidth);
91+
}
92+
93+
if (this._state.minHeight || this._state.minHeight === 0) {
94+
this._pane.style.minHeight = formatCssUnit(this._state.minHeight);
95+
}
8896
}
8997

9098
/** Attaches a backdrop for this overlay. */

src/lib/core/overlay/overlay-state.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export class OverlayState {
2222
/** The height of the overlay panel. If a number is provided, pixel units are assumed. **/
2323
height: number | string;
2424

25+
/** The min-width of the overlay panel. If a number is provided, pixel units are assumed. **/
26+
minWidth: number | string;
27+
28+
/** The min-height of the overlay panel. If a number is provided, pixel units are assumed. **/
29+
minHeight: number | string;
30+
2531
/** The direction of the text in the overlay panel. */
2632
direction: LayoutDirection = 'ltr';
2733

src/lib/core/overlay/overlay.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ describe('Overlay', () => {
147147
expect(pane.style.height).toEqual('100vh');
148148
});
149149

150+
it('should apply the min width set in the config', () => {
151+
state.minWidth = 200;
152+
153+
overlay.create(state).attach(componentPortal);
154+
const pane = overlayContainerElement.children[0] as HTMLElement;
155+
expect(pane.style.minWidth).toEqual('200px');
156+
});
157+
158+
159+
it('should apply the min height set in the config', () => {
160+
state.minHeight = 500;
161+
162+
overlay.create(state).attach(componentPortal);
163+
const pane = overlayContainerElement.children[0] as HTMLElement;
164+
expect(pane.style.minHeight).toEqual('500px');
165+
});
166+
167+
150168
it('should support zero widths and heights', () => {
151169
state.width = 0;
152170
state.height = 0;

0 commit comments

Comments
 (0)