zurfyx / angular-custom-modal

Angular2+ Modal / Dialog (with inner component support).

Home Page:https://zurfyx.github.io/angular-custom-modal/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Esc key dosen't close dialog

niesteszeck opened this issue · comments

add this to modal.component:

  @HostListener('document:keydown', ['$event'])
  onKeyDownHandler(event: KeyboardEvent) {
    if (event.key === "Escape") {
      this.close()
    }
  }

Hey @niesteszeck, do you mind submitting that as a PR and I'll have it a look tomorrow, and also you'll be marked as a contributor?

Off the top of my head it looks OK but incomplete. We shouldn't be closing all modals when a key is pressed, but rather the top most.

Thank you for contribution!

Hi @zurfyx

I made the pull request #5, but include some bootstrap improvements also.

Regarding your concern that listening to ESC key close all modal, I din't think that before, I will try it, and work on a solution.

I add a nested modal to the example to test it and ESC key close all modals. Actually, click outside the modal, closes all modals to. Working on both things.

Finally I made a service that is in charge of closing modals on ESC key press and Click outside modal events.

PR #6 is merged.

I left you some final notes in here.

Thank you for your work!