diff --git a/utils/modal/full-screen-modal/full-screen-modal.component.ts b/utils/modal/full-screen-modal/full-screen-modal.component.ts index 59fb76b9..1eaddbb7 100644 --- a/utils/modal/full-screen-modal/full-screen-modal.component.ts +++ b/utils/modal/full-screen-modal/full-screen-modal.component.ts @@ -1,35 +1,25 @@ -import {Component, ElementRef, EventEmitter, Input, OnInit, Output} from "@angular/core"; +import {Component, ElementRef, EventEmitter, OnInit, Output} from "@angular/core"; +import {fromEvent, Subscription} from 'rxjs'; +import {delay} from "rxjs/operators"; @Component({ selector: 'fs-modal', template: ` -
- - - -
-
-
- {{title}} -
-
- - -
+
+
+ + + +
+
{{title}}
-
-
-
-
- - -
- - -
-
+
+
` @@ -45,30 +35,39 @@ export class FullScreenModalComponent implements OnInit { cancelEmitter: EventEmitter = new EventEmitter(); opened: boolean = false; private readonly element: any; + private subscriptions: any[] = []; constructor(private el: ElementRef) { this.element = el.nativeElement; } ngOnInit() { - if(typeof document !== "undefined") { + if (typeof document !== "undefined") { document.body.appendChild(this.element); + this.subscriptions.push(fromEvent(document, 'keydown').pipe(delay(1)).subscribe((event: KeyboardEvent) => { + this.close(); + })); } } ngOnDestroy(): void { this.element.remove(); + this.subscriptions.forEach(subscription => { + if (subscription instanceof Subscription) { + subscription.unsubscribe(); + } + }) } open() { - if(typeof document !== "undefined") { + if (typeof document !== "undefined") { this.opened = true; document.getElementsByTagName('html')[0].classList.add('fs-modal-open'); } } close() { - if(typeof document !== "undefined") { + if (typeof document !== "undefined") { this.opened = false; document.getElementsByTagName('html')[0].classList.remove('fs-modal-open'); this.cancelEmitter.emit();