filter element target on keyboard event

This commit is contained in:
pionnegru 2019-10-21 12:15:41 +03:00
parent 84b190a441
commit 4abb09c98f
4 changed files with 77 additions and 9 deletions

View File

@ -14,8 +14,8 @@
[canNavigateNext]="nextNodeId" [canNavigateNext]="nextNodeId"
[overlayMode]="true" [overlayMode]="true"
(showViewerChange)="onVisibilityChanged($event)" (showViewerChange)="onVisibilityChanged($event)"
(navigateBefore)="onNavigateBefore()" (navigateBefore)="onNavigateBefore($event)"
(navigateNext)="onNavigateNext()" (navigateNext)="onNavigateNext($event)"
> >
<adf-viewer-sidebar *ngIf="infoDrawerOpened$ | async"> <adf-viewer-sidebar *ngIf="infoDrawerOpened$ | async">
<aca-info-drawer [node]="selection.file"></aca-info-drawer> <aca-info-drawer [node]="selection.file"></aca-info-drawer>

View File

@ -113,6 +113,11 @@ export class PreviewComponent extends PageComponent
'-TYPE:"lnk:link"' '-TYPE:"lnk:link"'
]; ];
private containersSkipNavigation = [
'adf-viewer__sidebar',
'mat-dialog-container'
];
constructor( constructor(
private contentApi: ContentApiService, private contentApi: ContentApiService,
private preferences: UserPreferencesService, private preferences: UserPreferencesService,
@ -258,7 +263,14 @@ export class PreviewComponent extends PageComponent
} }
/** Handles navigation to a previous document */ /** Handles navigation to a previous document */
onNavigateBefore(): void { onNavigateBefore(event: MouseEvent | KeyboardEvent): void {
if (
event.type !== 'click' &&
this.shouldNavigate(event.target as HTMLElement)
) {
return;
}
if (this.previousNodeId) { if (this.previousNodeId) {
this.router.navigate( this.router.navigate(
this.getPreviewPath(this.folderId, this.previousNodeId) this.getPreviewPath(this.folderId, this.previousNodeId)
@ -267,7 +279,14 @@ export class PreviewComponent extends PageComponent
} }
/** Handles navigation to a next document */ /** Handles navigation to a next document */
onNavigateNext(): void { onNavigateNext(event: MouseEvent | KeyboardEvent): void {
if (
event.type !== 'click' &&
this.shouldNavigate(event.target as HTMLElement)
) {
return;
}
if (this.nextNodeId) { if (this.nextNodeId) {
this.router.navigate(this.getPreviewPath(this.folderId, this.nextNodeId)); this.router.navigate(this.getPreviewPath(this.folderId, this.nextNodeId));
} }
@ -487,4 +506,20 @@ export class PreviewComponent extends PageComponent
return acc; return acc;
}, []); }, []);
} }
private shouldNavigate(element: HTMLElement): boolean {
let currentElement = element.parentElement;
while (currentElement && !this.isChild(currentElement.classList)) {
currentElement = currentElement.parentElement;
}
return !!currentElement;
}
private isChild(list: DOMTokenList): boolean {
return Array.from(list).some((className: string) =>
this.containersSkipNavigation.includes(className)
);
}
} }

View File

@ -15,8 +15,8 @@
(showViewerChange)="onViewerVisibilityChanged()" (showViewerChange)="onViewerVisibilityChanged()"
[canNavigateBefore]="previousNodeId" [canNavigateBefore]="previousNodeId"
[canNavigateNext]="nextNodeId" [canNavigateNext]="nextNodeId"
(navigateBefore)="onNavigateBefore()" (navigateBefore)="onNavigateBefore($event)"
(navigateNext)="onNavigateNext()" (navigateNext)="onNavigateNext($event)"
> >
<adf-viewer-sidebar *ngIf="infoDrawerOpened$ | async"> <adf-viewer-sidebar *ngIf="infoDrawerOpened$ | async">
<aca-info-drawer [node]="selection.file"></aca-info-drawer> <aca-info-drawer [node]="selection.file"></aca-info-drawer>

View File

@ -112,6 +112,10 @@ export class AppViewerComponent implements OnInit, OnDestroy {
fileName: string; fileName: string;
private previewLocation: string; private previewLocation: string;
private containersSkipNavigation = [
'adf-viewer__sidebar',
'mat-dialog-container'
];
constructor( constructor(
private router: Router, private router: Router,
@ -237,13 +241,26 @@ export class AppViewerComponent implements OnInit, OnDestroy {
} }
} }
onNavigateBefore(): void { onNavigateBefore(event: MouseEvent | KeyboardEvent): void {
const location = this.getFileLocation(); if (
event.type !== 'click' &&
this.shouldNavigate(event.target as HTMLElement)
) {
return;
}
const location = this.getFileLocation();
this.store.dispatch(new ViewNodeAction(this.previousNodeId, { location })); this.store.dispatch(new ViewNodeAction(this.previousNodeId, { location }));
} }
onNavigateNext(): void { onNavigateNext(event: MouseEvent | KeyboardEvent): void {
if (
event.type !== 'click' &&
this.shouldNavigate(event.target as HTMLElement)
) {
return;
}
const location = this.getFileLocation(); const location = this.getFileLocation();
this.store.dispatch(new ViewNodeAction(this.nextNodeId, { location })); this.store.dispatch(new ViewNodeAction(this.nextNodeId, { location }));
} }
@ -437,4 +454,20 @@ export class AppViewerComponent implements OnInit, OnDestroy {
.parseUrl(this.navigationPath || this.router.url) .parseUrl(this.navigationPath || this.router.url)
.root.children[PRIMARY_OUTLET].toString(); .root.children[PRIMARY_OUTLET].toString();
} }
private shouldNavigate(element: HTMLElement): boolean {
let currentElement = element.parentElement;
while (currentElement && !this.isChild(currentElement.classList)) {
currentElement = currentElement.parentElement;
}
return !!currentElement;
}
private isChild(list: DOMTokenList): boolean {
return Array.from(list).some((className: string) =>
this.containersSkipNavigation.includes(className)
);
}
} }