Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close a mat dialog without a backdrop on clicking outside?

How Can I close the dialog in this stackblitz example (Minimal, Reproducible Example.) by clicking outside ?

This works fine if I remove the property hasBackdrop: false -> Working Stackblitz Example

like image 810
dota2pro Avatar asked Dec 10 '22 02:12

dota2pro


1 Answers

The standard approach for creating an Angular Material Dialog that closes when clicking outside the dialog box (while creating the appearance that there is no backdrop) is to use the built-in library CSS class cdk-overlay-transparent-backdrop and apply it using the MatDialogConfig property backdropClass.

The openDialog method would be:

openDialog(): void {
  const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
    backdropClass: 'cdk-overlay-transparent-backdrop',
    hasBackdrop: true,
    width: '250px'
  });
}

See Stackblitz Example

like image 107
Christopher Peisert Avatar answered Jun 04 '23 12:06

Christopher Peisert