diff --git a/src/app/components/confirmpopup/confirmpopup.ts b/src/app/components/confirmpopup/confirmpopup.ts index 41a3d4fc40c..a3be8543134 100755 --- a/src/app/components/confirmpopup/confirmpopup.ts +++ b/src/app/components/confirmpopup/confirmpopup.ts @@ -1,6 +1,23 @@ import { AnimationEvent, animate, state, style, transition, trigger } from '@angular/animations'; import { CommonModule, DOCUMENT } from '@angular/common'; -import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChildren, ElementRef, EventEmitter, Inject, Input, NgModule, OnDestroy, QueryList, Renderer2, TemplateRef, ViewEncapsulation } from '@angular/core'; +import { + AfterContentInit, + ChangeDetectionStrategy, + ChangeDetectorRef, + Component, + ContentChildren, + ElementRef, + EventEmitter, + HostListener, + Inject, + Input, + NgModule, + OnDestroy, + QueryList, + Renderer2, + TemplateRef, + ViewEncapsulation +} from '@angular/core'; import { Confirmation, ConfirmationService, OverlayService, PrimeNGConfig, PrimeTemplate, SharedModule, TranslationKeys } from 'primeng/api'; import { ButtonModule } from 'primeng/button'; import { ConnectedOverlayScrollHandler, DomHandler } from 'primeng/dom'; @@ -208,6 +225,13 @@ export class ConfirmPopup implements AfterContentInit, OnDestroy { }); } + @HostListener('document:keydown.escape', ['$event']) + onEscapeKeydown(event: KeyboardEvent) { + if (this.confirmation && this.confirmation.closeOnEscape) { + this.reject(); + } + } + onAnimationStart(event: AnimationEvent) { if (event.toState === 'open') { this.container = event.element;