Skip to content

Commit 8635804

Browse files
committed
feat(overlay): add maxWidth and maxHeight
1 parent 72360e2 commit 8635804

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/cdk/overlay/overlay-ref.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ export class OverlayRef implements PortalHost {
172172
if (this._state.minHeight || this._state.minHeight === 0) {
173173
this._pane.style.minHeight = formatCssUnit(this._state.minHeight);
174174
}
175+
176+
if (this._state.maxWidth || this._state.maxWidth === 0) {
177+
this._pane.style.maxWidth = formatCssUnit(this._state.maxWidth);
178+
}
179+
180+
if (this._state.maxHeight || this._state.maxHeight === 0) {
181+
this._pane.style.maxHeight = formatCssUnit(this._state.maxHeight);
182+
}
175183
}
176184

177185
/** Toggles the pointer events for the overlay pane element. */

src/cdk/overlay/overlay-state.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export class OverlayState {
4444
/** The min-height of the overlay panel. If a number is provided, pixel units are assumed. */
4545
minHeight?: number | string;
4646

47+
/** The max-width of the overlay panel. If a number is provided, pixel units are assumed. */
48+
maxWidth?: number | string;
49+
50+
/** The max-height of the overlay panel. If a number is provided, pixel units are assumed. */
51+
maxHeight?: number | string;
52+
4753
/** The direction of the text in the overlay panel. */
4854
direction?: Direction = 'ltr';
4955

src/cdk/overlay/overlay.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,22 @@ describe('Overlay', () => {
295295
expect(pane.style.minHeight).toEqual('500px');
296296
});
297297

298+
it('should apply the max width set in the config', () => {
299+
state.maxWidth = 200;
300+
301+
overlay.create(state).attach(componentPortal);
302+
const pane = overlayContainerElement.children[0] as HTMLElement;
303+
expect(pane.style.maxWidth).toEqual('200px');
304+
});
305+
306+
307+
it('should apply the max height set in the config', () => {
308+
state.maxHeight = 500;
309+
310+
overlay.create(state).attach(componentPortal);
311+
const pane = overlayContainerElement.children[0] as HTMLElement;
312+
expect(pane.style.maxHeight).toEqual('500px');
313+
});
298314

299315
it('should support zero widths and heights', () => {
300316
state.width = 0;
@@ -305,7 +321,6 @@ describe('Overlay', () => {
305321
expect(pane.style.width).toEqual('0px');
306322
expect(pane.style.height).toEqual('0px');
307323
});
308-
309324
});
310325

311326
describe('backdrop', () => {

0 commit comments

Comments
 (0)