Bug: MdDialog not centered when is open passing a configuration of a custom width.
MdDialog should be the size of the specified width but keep his center location.
MdDialog is being moved to the left.
https://plnkr.co/edit/fvG6lS8VIihJUlfu01Bv?p=preview
openDialog() {
this.dialog.open(DialogOverviewExampleDialog, {
width: '600px'
});
}
Material 2.0.0-beta.2
Chrome in Windows
This happens when the dialog hits the max width and is an issue with how we have the dialog set up in general. I'll be reworking it once https://github.com/angular/material2/pull/3184 is merged.
@crisbeto Is there a known workaround for this at the moment? Is there a way to apply styling to ".mat-dialog-container" for now that I'm unaware of? When I attempt to set a style to that class in my styleUrl sheet, it is ignored, since it is launched after the page is loaded from a button click.
There is no nice workaround @ryanpm40. Technically adding a max-width
to the .cdk-overlay-pane
should fix it, but the cdk-overlay-pane
is used for all overlay-based Material components. Now that #3184 is merged, I can do a proper fix for it, though.
@crisbeto Gotcha, thanks for the update! I suppose another temporary option for me would be to use some javascript to get the class element (but obviously not very ideal):
let containerElem:HTMLElement = <HTMLElement>document.getElementsByClassName('mat-dialog-container')[0];
containerElem.style.width="900px";
Looking forward to those changes :)
I like the current behaviour that it get shrinked when the config's width
gets hit, since a dialog should never be larger than screen I guess!?
Only problem is that it isn't centered anymore then.
Adding margin: auto
to .mat-dialog-container
does the trick.
So workaround for that is adding this to global stylesheet:
md-dialog-container {
margin: auto;
}
As another solution, you can add a panelClass
to the dialog and then apply whatever css just to that specific dialog.
this.dialog.open(MyDialogComponent, {
panelClass: 'my-full-screen-dialog',
data: { ... }
});
.my-full-screen-dialog .mat-dialog-container {
max-width: none;
width: 100vw;
height: 100vh;
}
thanks willshowell. This works well, and elegantly enough.
@willshowell , I was testing the feature above, but I must be doing something terribly wrong. I tried to change background color of the backdrop panel and/or of the panel, but it seems to have no effect at all.
Is it working properly? Plunker: https://plnkr.co/edit/OjPQdv6Txqcn1v5nXG3p?p=preview
@julianobrasil the styles must be global or without view encapsulation 馃榿
Most helpful comment
As another solution, you can add a
panelClass
to the dialog and then apply whatever css just to that specific dialog.