Skip to content

Commit

Permalink
[primefaces#13305] - Fixed ESC button close preview on image Component
Browse files Browse the repository at this point in the history
  • Loading branch information
SoyDiego committed Jul 9, 2023
1 parent e1f8c18 commit 0facc2d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/app/components/image/image.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AnimationEvent, animate, style, transition, trigger } from '@angular/animations';
import { CommonModule, DOCUMENT } from '@angular/common';
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChildren, ElementRef, EventEmitter, Inject, Input, NgModule, Output, QueryList, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core';
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChildren, ElementRef, EventEmitter, HostListener, Inject, Input, NgModule, Output, QueryList, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core';
import { SafeUrl } from '@angular/platform-browser';
import { PrimeNGConfig, PrimeTemplate, SharedModule } from 'primeng/api';
import { DomHandler } from 'primeng/dom';
Expand Down Expand Up @@ -199,7 +199,7 @@ export class Image implements AfterContentInit {
min: 0.5
};

constructor(@Inject(DOCUMENT) private document: Document, private config: PrimeNGConfig, private cd: ChangeDetectorRef) {}
constructor(@Inject(DOCUMENT) private document: Document, private config: PrimeNGConfig, private cd: ChangeDetectorRef) { }

ngAfterContentInit() {
this.templates?.forEach((item) => {
Expand Down Expand Up @@ -340,11 +340,17 @@ export class Image implements AfterContentInit {
imageError(event: Event) {
this.onImageError.emit(event);
}

@HostListener('document:keydown.escape', ['$event']) onKeydownHandler(event: KeyboardEvent) {
if (this.previewVisible) {
this.closePreview();
}
}
}

@NgModule({
imports: [CommonModule, SharedModule, RefreshIcon, EyeIcon, UndoIcon, SearchMinusIcon, SearchPlusIcon, TimesIcon],
exports: [Image, SharedModule],
declarations: [Image]
})
export class ImageModule {}
export class ImageModule { }

0 comments on commit 0facc2d

Please sign in to comment.