Skip to content

Decouple backdrop click and ESC press on mat-dialog #10190

Closed

Description

@salemdar

Feature request:

Both ESC and backdrop click closes an active dialog. This can be disabled at the moment, but only all together. These two behaviours should be decoupled.

What is the expected behavior?

MatDialogConfig should have 2 extra properties:

// ...
disableCloseOnEscape: boolean,
disableCloseOnBackdropClick: boolean

What is the use-case or motivation for changing an existing behavior?

So we can disable closing on backdrop click, but keep close on ESC press. It would be very helpful for inaccurate mouse users :).

Activity

  1. changed the title [-]Decouple backdrop click and <kbd>ESC</kbd> press on mat-dialog[/-] [+]Decouple backdrop click and ESC press on mat-dialog[/+] on Feb 28, 2018
  2. willshowell commented on Feb 28, 2018

    @willshowell
    Contributor

    The suggested approach for this is to set disableClose and then use keydownEvents or backdropClick to re-enable the desired behavior.

    See #3460 and linked threads for more context.

  3. salemdar commented on Feb 28, 2018

    @salemdar
    Author

    @willshowell thanks for your comment. I am aware that there are possible workarounds. For example, I wrote something like this:

    const dialogRef = this.dialog.open(MyDialogComponent, {
      disableClose: true
    });
    dialogRef.keydownEvents()
      .filter((e: KeyboardEvent) => e.code === 'Escape')
      .take(1)
      .subscribe(() => dialogRef.close());

    But wouldn't it be nice to have it out of box? I believe it could be useful for many people.

  4. willshowell commented on Feb 28, 2018

    @willshowell
    Contributor

    @salemdar the team (at least in the past) has held pretty strong to this. See #3460 (comment) for a better explanation than I can give.

  5. jelbourn commented on Mar 1, 2018

    @jelbourn
    Contributor

    Yep, as per Will's comment, we don't really want to decouple these behaviors.

  6. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  7. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions