Hello my beloved community,
Using angular with angular material.
With the default configuration when you open up a material dialog, it darkens the background a bit. Now I would like it to be a blurred background instead. I tried playing around with the css styles but I could not get the background of the window to change (couldn't get the right selector inside of component template).
I went through the documentation but there is nothing there. I can play a little bit more with the styles since I am sure there is probably some tricky way but considering the darkening effect is already there out of the box I would assume there should be a theming feature available out of the box as well. What you think?
In order to use the Angular Material Dialog, we will first need to import MatDialogModule: ... ... ... Notice also CourseDialogComponent, this component will be the body of our custom dialog.
The Angular Material components library comes bundled with a few themes which we can use for your app. But for adding a dark mode, you need to add a custom theme file instead. A sample custom theme looks like the following.
mat-dialog-container { background-color: greenyellow !important; } another way is changing Material theme globally in styles.scss. if you want to change background color different for dialogs, set background color of = transparency. then set background color for dialog component.
This prebuilt theme is intentionally a dark theme. If you're not intending to use this theme, there are still 2 other light themes that you can choose from: indigo-pink.css or deeppurple-amber.css. Check out the theming guide for more info: material.angular.io/guide/theming#using-a-pre-built-theme
I guess you've missed the property MatDialogConfig - backdropClass in the docs.
Check this StackBlitz DEMO for a simple example
From this DEMO:
dialog-overview-example.ts:
openDialog(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: {name: this.name, animal: this.animal},
backdropClass: 'backdropBackground' // This is the "wanted" line
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
styles.css:
.backdropBackground {
/* your css needs */
}
The given answer by @benshabatnoam is absolutely correct, but the documentation also has another option to disable the backdrop altogether.
hasBackdrop
Here is an example:
https://stackblitz.com/edit/angular-ei9hdv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With