Skip to content

Commit

Permalink
Merge pull request #13675 from SoyDiego/13652-Fixed-closeOnEscape-con…
Browse files Browse the repository at this point in the history
…firmPopup

ConfirmPopup: Add hostListener to closeOnEscape
  • Loading branch information
cetincakiroglu authored Sep 22, 2023
2 parents 1cbcf73 + 5ad1425 commit 63b9ffa
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/app/components/confirmpopup/confirmpopup.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down

1 comment on commit 63b9ffa

@vercel
Copy link

@vercel vercel bot commented on 63b9ffa Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.