[ACS-3757] returning focus to element from which they were opened (#8034)

* ACS-3757 Focus first focusable element in modals and allow to autofocus specific element after modal closing

* ACS-3757 Added possibility for autofocus after closing some modals, marking datatable row as source of context menu, fixing tests

* ACS-3757 Run lint

* ACS-3757 Updated documentation

* ACS-3757 Added unit tests

* ACS-3757 Replaced toHaveBeenCalledWith with toHaveBeenCalled and removed testing all falsy
This commit is contained in:
AleksanderSklorz
2022-12-13 11:55:46 +01:00
committed by GitHub
parent ef278bde79
commit c1cffa9cfb
12 changed files with 164 additions and 11 deletions

View File

@@ -51,9 +51,10 @@ export class NewVersionUploaderService {
*
* @param data data to pass to MatDialog
* @param config allow to override default MatDialogConfig
* @param selectorAutoFocusedOnClose element's selector which should be autofocused after closing modal
* @returns an Observable represents the triggered dialog action or an error in case of an error condition
*/
openUploadNewVersionDialog(data: NewVersionUploaderDialogData, config?: MatDialogConfig) {
openUploadNewVersionDialog(data: NewVersionUploaderDialogData, config?: MatDialogConfig, selectorAutoFocusedOnClose?: string) {
const { file, node, showVersionsOnly } = data;
const showComments = true;
const allowDownload = true;
@@ -76,6 +77,7 @@ export class NewVersionUploaderService {
});
dialogRef.afterClosed().subscribe(() => {
this.overlayContainer.getContainerElement().setAttribute('role', 'region');
NewVersionUploaderService.focusOnClose(selectorAutoFocusedOnClose);
});
this.overlayContainer.getContainerElement().setAttribute('role', 'main');
});
@@ -90,4 +92,10 @@ export class NewVersionUploaderService {
const dialogCssClass = 'adf-new-version-uploader-dialog';
return [dialogCssClass, `${dialogCssClass}-${showVersionsOnly ? 'list' : 'upload'}`];
}
private static focusOnClose(selectorAutoFocusedOnClose: string): void {
if (selectorAutoFocusedOnClose) {
document.querySelector<HTMLElement>(selectorAutoFocusedOnClose).focus();
}
}
}