Skip to content

feat(overlay): add maxWidth and maxHeight #6508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cdk/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ export class OverlayRef implements PortalHost {
if (this._state.minHeight || this._state.minHeight === 0) {
this._pane.style.minHeight = formatCssUnit(this._state.minHeight);
}

if (this._state.maxWidth || this._state.maxWidth === 0) {
this._pane.style.maxWidth = formatCssUnit(this._state.maxWidth);
}

if (this._state.maxHeight || this._state.maxHeight === 0) {
this._pane.style.maxHeight = formatCssUnit(this._state.maxHeight);
}
}

/** Toggles the pointer events for the overlay pane element. */
Expand Down
6 changes: 6 additions & 0 deletions src/cdk/overlay/overlay-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export class OverlayState {
/** The min-height of the overlay panel. If a number is provided, pixel units are assumed. */
minHeight?: number | string;

/** The max-width of the overlay panel. If a number is provided, pixel units are assumed. */
maxWidth?: number | string;

/** The max-height of the overlay panel. If a number is provided, pixel units are assumed. */
maxHeight?: number | string;

/** The direction of the text in the overlay panel. */
direction?: Direction = 'ltr';

Expand Down
17 changes: 16 additions & 1 deletion src/cdk/overlay/overlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ describe('Overlay', () => {
expect(pane.style.minHeight).toEqual('500px');
});

it('should apply the max width set in the config', () => {
state.maxWidth = 200;

overlay.create(state).attach(componentPortal);
const pane = overlayContainerElement.children[0] as HTMLElement;
expect(pane.style.maxWidth).toEqual('200px');
});


it('should apply the max height set in the config', () => {
state.maxHeight = 500;

overlay.create(state).attach(componentPortal);
const pane = overlayContainerElement.children[0] as HTMLElement;
expect(pane.style.maxHeight).toEqual('500px');
});

it('should support zero widths and heights', () => {
state.width = 0;
Expand All @@ -305,7 +321,6 @@ describe('Overlay', () => {
expect(pane.style.width).toEqual('0px');
expect(pane.style.height).toEqual('0px');
});

});

describe('backdrop', () => {
Expand Down