[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
This commit is contained in:
AleksanderSklorz 2022-11-24 13:18:07 +01:00 committed by GitHub
parent 692952aa31
commit 43b96fc796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View File

@ -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<HTMLElement>('app-create-menu button').focus();
}
}

View File

@ -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(() => {

View File

@ -116,11 +116,13 @@ export class NodeTemplateService {
}
createTemplateDialog(node: Node): MatDialogRef<CreateFromTemplateDialogComponent> {
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<HTMLElement>('app-create-menu button').focus();
}
}