-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(dialog): allow for the dialog dimensions to be updated #2940
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
Changes from 2 commits
02daf3f
fc6d7c3
6b9b163
4f44a3d
946397d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,6 +274,38 @@ describe('MdDialog', () => { | |
expect(overlayPane.style.marginRight).toBe('125px'); | ||
}); | ||
|
||
it('should allow for the position to be updated', () => { | ||
let dialogRef = dialog.open(PizzaMsg, { | ||
position: { | ||
left: '250px' | ||
} | ||
}); | ||
|
||
viewContainerFixture.detectChanges(); | ||
|
||
let overlayPane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement; | ||
|
||
expect(overlayPane.style.marginLeft).toBe('250px'); | ||
|
||
dialogRef.updatePosition({ left: '500px' }); | ||
|
||
expect(overlayPane.style.marginLeft).toBe('500px'); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably need tests for updating the width and height as well. |
||
|
||
it('should allow for the dimensions to be updated', () => { | ||
let dialogRef = dialog.open(PizzaMsg, { width: '100px' }); | ||
|
||
viewContainerFixture.detectChanges(); | ||
|
||
let overlayPane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement; | ||
|
||
expect(overlayPane.style.width).toBe('100px'); | ||
|
||
dialogRef.updateDimensions('200px'); | ||
|
||
expect(overlayPane.style.width).toBe('200px'); | ||
}); | ||
|
||
it('should close all of the dialogs', async(() => { | ||
dialog.open(PizzaMsg); | ||
dialog.open(PizzaMsg); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,11 +92,16 @@ export class MdDialog { | |
|
||
/** | ||
* Creates the overlay into which the dialog will be loaded. | ||
* @param dialogConfig The dialog configuration. | ||
* @param config The dialog configuration. | ||
* @returns A promise resolving to the OverlayRef for the created overlay. | ||
*/ | ||
private _createOverlay(dialogConfig: MdDialogConfig): OverlayRef { | ||
let overlayState = this._getOverlayState(dialogConfig); | ||
private _createOverlay(config: MdDialogConfig): OverlayRef { | ||
let overlayState = new OverlayState(); | ||
let strategy = this._overlay.position().global(); | ||
|
||
overlayState.hasBackdrop = true; | ||
overlayState.positionStrategy = strategy; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not removed, I've moved it to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I just meant this could still be private _getOverlayState(dialogConfig: MdDialogConfig): OverlayState {
let overlayState = new OverlayState();
overlayState.hasBackdrop = true;
overlayState.positionStrategy = this._overlay.position().global();
return overlayState;
} |
||
|
||
return this._overlay.create(overlayState); | ||
} | ||
|
||
|
@@ -129,10 +134,11 @@ export class MdDialog { | |
componentOrTemplateRef: ComponentType<T> | TemplateRef<T>, | ||
dialogContainer: MdDialogContainer, | ||
overlayRef: OverlayRef, | ||
config?: MdDialogConfig): MdDialogRef<T> { | ||
config: MdDialogConfig): MdDialogRef<T> { | ||
// Create a reference to the dialog we're creating in order to give the user a handle | ||
// to modify and close it. | ||
let dialogRef = new MdDialogRef(overlayRef, dialogContainer) as MdDialogRef<T>; | ||
|
||
let dialogRef = new MdDialogRef<T>(overlayRef, dialogContainer); | ||
|
||
if (!config.disableClose) { | ||
// When the dialog backdrop is clicked, we want to close it. | ||
|
@@ -153,37 +159,11 @@ export class MdDialog { | |
dialogRef.componentInstance = contentRef.instance; | ||
} | ||
|
||
return dialogRef; | ||
} | ||
|
||
/** | ||
* Creates an overlay state from a dialog config. | ||
* @param dialogConfig The dialog configuration. | ||
* @returns The overlay configuration. | ||
*/ | ||
private _getOverlayState(dialogConfig: MdDialogConfig): OverlayState { | ||
let state = new OverlayState(); | ||
let strategy = this._overlay.position().global(); | ||
let position = dialogConfig.position; | ||
|
||
state.hasBackdrop = true; | ||
state.positionStrategy = strategy; | ||
|
||
if (position && (position.left || position.right)) { | ||
position.left ? strategy.left(position.left) : strategy.right(position.right); | ||
} else { | ||
strategy.centerHorizontally(); | ||
} | ||
|
||
if (position && (position.top || position.bottom)) { | ||
position.top ? strategy.top(position.top) : strategy.bottom(position.bottom); | ||
} else { | ||
strategy.centerVertically(); | ||
} | ||
dialogRef | ||
.updateDimensions(config.width, config.height) | ||
.updatePosition(config.position); | ||
|
||
strategy.width(dialogConfig.width).height(dialogConfig.height); | ||
|
||
return state; | ||
return dialogRef; | ||
} | ||
|
||
/** | ||
|
@@ -221,10 +201,10 @@ export class MdDialog { | |
|
||
/** | ||
* Applies default options to the dialog config. | ||
* @param dialogConfig Config to be modified. | ||
* @param config Config to be modified. | ||
* @returns The new configuration object. | ||
*/ | ||
function _applyConfigDefaults(dialogConfig: MdDialogConfig): MdDialogConfig { | ||
return extendObject(new MdDialogConfig(), dialogConfig); | ||
function _applyConfigDefaults(config: MdDialogConfig): MdDialogConfig { | ||
return extendObject(new MdDialogConfig(), config); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateSize
?