Skip to content

Commit a023f45

Browse files
committed
feat(overlay): set overlay size
1 parent add0d23 commit a023f45

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class OverlayRef implements PortalHost {
2323
}
2424

2525
let attachResult = this._portalHost.attach(portal);
26+
this.updateSize();
2627
this.updatePosition();
2728

2829
return attachResult;
@@ -58,6 +59,17 @@ export class OverlayRef implements PortalHost {
5859
}
5960
}
6061

62+
/** Updates the size of the overlay based on the overlay config. */
63+
updateSize() {
64+
if (this._state.width) {
65+
this._pane.style.width = `${this._state.width}px`;
66+
}
67+
68+
if (this._state.height) {
69+
this._pane.style.height = `${this._state.height}px`;
70+
}
71+
}
72+
6173
/** Attaches a backdrop for this overlay. */
6274
private _attachBackdrop() {
6375
this._backdropElement = document.createElement('div');

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ export class OverlayState {
1212
/** Whether the overlay has a backdrop. */
1313
hasBackdrop: boolean = false;
1414

15+
/** Custom class to add to the backdrop **/
1516
backdropClass: string = 'md-overlay-dark-backdrop';
1617

18+
/** The width of the overlay panel **/
19+
width: number;
20+
21+
/** The height of the overlay panel **/
22+
height: number;
23+
1724
// TODO(jelbourn): configuration still to add
18-
// - overlay size
1925
// - focus trap
2026
// - disable pointer events
2127
// - z-index

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,30 @@ describe('Overlay', () => {
9898
});
9999
});
100100

101+
describe('size', () => {
102+
let state: OverlayState;
103+
104+
beforeEach(() => {
105+
state = new OverlayState();
106+
});
107+
108+
it('should apply the width set in the config', () => {
109+
state.width = 500;
110+
111+
overlay.create(state).attach(componentPortal);
112+
const pane = (<HTMLElement>overlayContainerElement.children[0]);
113+
expect(pane.style.width).toEqual('500px');
114+
});
115+
116+
it('should apply the height set in the config', () => {
117+
state.height = 500;
118+
119+
overlay.create(state).attach(componentPortal);
120+
const pane = (<HTMLElement>overlayContainerElement.children[0]);
121+
expect(pane.style.height).toEqual('500px');
122+
});
123+
});
124+
101125
describe('backdrop', () => {
102126
let config: OverlayState;
103127

0 commit comments

Comments
 (0)