[ACA-2176] prevent Esc click event bubble into the Viewer (#6378)

* prevent Esc click event bubble into the Viewer

* fix tests
This commit is contained in:
Denys Vuika
2020-12-02 13:48:44 +00:00
committed by GitHub
parent 567ea6cb0d
commit a3fabf632c
5 changed files with 45 additions and 11 deletions

View File

@@ -15,10 +15,11 @@
* limitations under the License.
*/
import { Component, Inject, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { TranslationService, NotificationService, AllowableOperationsEnum, ContentService } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api';
import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface';
import { NodeEntryEvent } from '../document-list/components/node.event';
@@ -28,7 +29,7 @@ import { NodeEntryEvent } from '../document-list/components/node.event';
styleUrls: ['./content-node-selector.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class ContentNodeSelectorComponent {
export class ContentNodeSelectorComponent implements OnInit {
title: string;
action: string;
buttonActionName: string;
@@ -41,6 +42,7 @@ export class ContentNodeSelectorComponent {
constructor(private translation: TranslationService,
private contentService: ContentService,
private notificationService: NotificationService,
private dialog: MatDialogRef<ContentNodeSelectorComponent>,
@Inject(MAT_DIALOG_DATA) public data: ContentNodeSelectorComponentData) {
this.action = data.actionName ? data.actionName.toUpperCase() : 'CHOOSE';
this.buttonActionName = `NODE_SELECTOR.${this.action}`;
@@ -48,6 +50,21 @@ export class ContentNodeSelectorComponent {
this.currentDirectoryId = data.currentFolderId;
}
ngOnInit() {
this.dialog.keydownEvents().subscribe(event => {
// Esc
if (event.keyCode === 27) {
event.preventDefault();
event.stopImmediatePropagation();
this.close();
}
});
this.dialog.backdropClick().subscribe(() => {
this.close();
});
}
close() {
this.data.select.complete();
}