Skip to content

Commit 9904e56

Browse files
jelbournkara
authored andcommitted
feat(overlay): add maxWidth and maxHeight (#6508)
1 parent 0db3635 commit 9904e56

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
@@ -176,6 +176,14 @@ export class OverlayRef implements PortalHost {
176176
if (this._state.minHeight || this._state.minHeight === 0) {
177177
this._pane.style.minHeight = formatCssUnit(this._state.minHeight);
178178
}
179+
180+
if (this._state.maxWidth || this._state.maxWidth === 0) {
181+
this._pane.style.maxWidth = formatCssUnit(this._state.maxWidth);
182+
}
183+
184+
if (this._state.maxHeight || this._state.maxHeight === 0) {
185+
this._pane.style.maxHeight = formatCssUnit(this._state.maxHeight);
186+
}
179187
}
180188

181189
/** 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)