From 43b96fc796df7bdf77cfa9312ae32e66b05eb071 Mon Sep 17 00:00:00 2001 From: AleksanderSklorz <115619721+AleksanderSklorz@users.noreply.github.com> Date: Thu, 24 Nov 2022 13:18:07 +0100 Subject: [PATCH] [ACS-3758] 880526 modal is closed focus is not returned to trigger in the create new menu (#2809) * ACS-3758 Return focus to New button after closing dialog opened from New menu * ACS-3758 Fixed unit tests --- .../services/content-management.service.ts | 6 ++++++ .../services/node-template.service.spec.ts | 1 + .../app/content-plugin/services/node-template.service.ts | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/app/content-plugin/services/content-management.service.ts b/app/src/app/content-plugin/services/content-management.service.ts index 6d5976766..4a4db6e6e 100644 --- a/app/src/app/content-plugin/services/content-management.service.ts +++ b/app/src/app/content-plugin/services/content-management.service.ts @@ -237,6 +237,7 @@ export class ContentManagementService { if (node) { this.store.dispatch(new ReloadDocumentListAction()); } + ContentManagementService.focusCreateMenuButton(); }); } @@ -277,6 +278,7 @@ export class ContentManagementService { if (node) { this.appHookService.libraryCreated.next(node); } + ContentManagementService.focusCreateMenuButton(); }), map((node: SiteEntry) => { if (node && node.entry && node.entry.guid) { @@ -1077,4 +1079,8 @@ export class ContentManagementService { .onAction() .subscribe(() => this.undoMoveNodes(moveResponse, initialParentId)); } + + private static focusCreateMenuButton(): void { + document.querySelector('app-create-menu button').focus(); + } } diff --git a/app/src/app/content-plugin/services/node-template.service.spec.ts b/app/src/app/content-plugin/services/node-template.service.spec.ts index 62c8ce7ff..88f910cee 100644 --- a/app/src/app/content-plugin/services/node-template.service.spec.ts +++ b/app/src/app/content-plugin/services/node-template.service.spec.ts @@ -55,6 +55,7 @@ describe('NodeTemplateService', () => { store = TestBed.inject(Store); dialog = TestBed.inject(MatDialog); nodeTemplateService = TestBed.inject(NodeTemplateService); + spyOn(document, 'querySelector').and.returnValue(document.createElement('button')); }); it('should open dialog with parent node `id` as data property', fakeAsync(() => { diff --git a/app/src/app/content-plugin/services/node-template.service.ts b/app/src/app/content-plugin/services/node-template.service.ts index 9a7db03fb..c55268d11 100644 --- a/app/src/app/content-plugin/services/node-template.service.ts +++ b/app/src/app/content-plugin/services/node-template.service.ts @@ -116,11 +116,13 @@ export class NodeTemplateService { } createTemplateDialog(node: Node): MatDialogRef { - return this.dialog.open(CreateFromTemplateDialogComponent, { + const dialog = this.dialog.open(CreateFromTemplateDialogComponent, { data: node, panelClass: 'aca-create-from-template-dialog', width: '630px' }); + dialog.afterClosed().subscribe(() => NodeTemplateService.focusCreateMenuButton()); + return dialog; } private transformNode(node: MinimalNode): MinimalNode { @@ -144,6 +146,7 @@ export class NodeTemplateService { private close() { this.dialog.closeAll(); + NodeTemplateService.focusCreateMenuButton(); } private title(selectionType: string) { @@ -162,4 +165,8 @@ export class NodeTemplateService { private getPathElements(node: Node): PathElement[] { return node.path.elements.filter((pathElement) => !this.rootNode.path.elements.some((rootPathElement) => pathElement.id === rootPathElement.id)); } + + private static focusCreateMenuButton(): void { + document.querySelector('app-create-menu button').focus(); + } }