Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Handle disabled

Oliver Güntherf7b5b350e9df
diff --git a/frontend/src/app/shared/components/autocompleter/project-menu-autocomplete/project-menu-autocomplete.template.html b/frontend/src/app/shared/components/autocompleter/project-menu-autocomplete/project-menu-autocomplete.template.html
index 3f35817b2cc..76980ca6097 100644
--- a/frontend/src/app/shared/components/autocompleter/project-menu-autocomplete/project-menu-autocomplete.template.html
+++ b/frontend/src/app/shared/components/autocompleter/project-menu-autocomplete/project-menu-autocomplete.template.html
@@ -49,6 +49,7 @@
[projects]="projects$ | async"
[searchText]="searchableProjectListService.searchText"
[multiSelect]="false"
+ data-list-root="true"
data-qa-selector="op-project-menu-autocomplete--list"
></ul>
</ng-container>
diff --git a/frontend/src/app/shared/components/project-include/project-include.component.html b/frontend/src/app/shared/components/project-include/project-include.component.html
index fef996953b0..ff3b32d26c4 100644
--- a/frontend/src/app/shared/components/project-include/project-include.component.html
+++ b/frontend/src/app/shared/components/project-include/project-include.component.html
@@ -57,6 +57,7 @@
[root]="true"
(update)="selectedProjects = $event"
data-qa-selector="project-include-list"
+ data-list-root="true"
></ul>
</ng-container>
diff --git a/frontend/src/app/shared/components/project-list/project-list.component.html b/frontend/src/app/shared/components/project-list/project-list.component.html
index 1d225152a04..7b2328474d1 100644
--- a/frontend/src/app/shared/components/project-list/project-list.component.html
+++ b/frontend/src/app/shared/components/project-list/project-list.component.html
@@ -2,12 +2,14 @@
class="spot-list--item"
*ngFor="let project of projects; index as i; first as isFirst; last as isLast"
data-qa-selector="op-project-list--item"
+ [attr.data-list-selector]="projectListItemIdentifier"
>
<label
*ngIf="multiSelect"
class="spot-list--item-action op-project-list--item-action"
[ngClass]="{ 'spot-list--item-action_disabled': isDisabled(project) }"
- [attr.data-list-action-selector]="projectListActionIdentifier"
+ [attr.data-list-selector]="projectListActionIdentifier"
+ [attr.data-list-disabled]="isDisabled(project) || undefined"
>
<spot-tooltip
class="op-project-list--tooltip"
diff --git a/frontend/src/app/shared/components/project-list/project-list.component.ts b/frontend/src/app/shared/components/project-list/project-list.component.ts
index 41a5af7931d..d2dce1b725a 100644
--- a/frontend/src/app/shared/components/project-list/project-list.component.ts
+++ b/frontend/src/app/shared/components/project-list/project-list.component.ts
@@ -12,8 +12,12 @@ import SpotDropAlignmentOption from 'core-app/spot/drop-alignment-options';
import { IProjectData } from './project-data';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-export const projectListActionIdentifier:string = 'op-project-list--item-action';
-export const projectListActionSelector:string = `[data-list-action-selector='${projectListActionIdentifier}']`;
+export const projectListActionIdentifier = 'op-project-list-action';
+export const projectListItemIdentifier = 'op-project-list-item';
+export const projectListActionSelector = `[data-list-selector='${projectListActionIdentifier}']`;
+export const projectListItemSelector = `[data-list-selector='${projectListItemIdentifier}']`;
+export const projectListItemDisabled = '[data-list-disabled="true"]';
+export const projectListRootSelector = '[data-list-root="true"]';
@Component({
selector: '[op-project-list]',
@@ -53,6 +57,7 @@ export class OpProjectListComponent {
};
projectListActionIdentifier = projectListActionIdentifier;
+ projectListItemIdentifier = projectListItemIdentifier;
constructor(
readonly I18n:I18nService,
diff --git a/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.ts b/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.ts
index c48dc81e974..875efc50571 100644
--- a/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.ts
+++ b/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.ts
@@ -12,7 +12,12 @@ import { finalize } from 'rxjs/operators';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { HttpClient } from '@angular/common/http';
import { KeyCodes } from 'core-app/shared/helpers/keyCodes.enum';
-import { projectListActionSelector } from 'core-app/shared/components/project-list/project-list.component';
+import {
+ projectListActionSelector,
+ projectListItemDisabled,
+ projectListItemSelector,
+ projectListRootSelector,
+} from 'core-app/shared/components/project-list/project-list.component';
@Injectable()
export class SearchableProjectListService {
@@ -78,7 +83,6 @@ export class SearchableProjectListService {
private handleKeyNavigation(upwards = false):void {
const focused = document.activeElement as HTMLElement|undefined;
- const items = document.querySelectorAll(`[data-list-action-selector='${projectListActionSelector}']`);
// If the current focus is within a list action, move focus in direction
if (focused?.closest(projectListActionSelector)) {
@@ -95,16 +99,46 @@ export class SearchableProjectListService {
private moveFocus(source:Element, upwards = false):void {
const activeItem = source.closest(projectListActionSelector) as HTMLElement;
- let nextContainer:Element|null|undefined;
+ let nextTarget = this.findNextTarget(activeItem, upwards);
- if (upwards) {
- nextContainer = activeItem.previousElementSibling || activeItem.closest('li')?.previousElementSibling;
- } else {
- nextContainer = activeItem?.nextElementSibling || activeItem.closest('li')?.nextElementSibling;
+ // If the target is disabled, skip
+ while (nextTarget?.matches(projectListItemDisabled)) {
+ nextTarget = this.findNextTarget(nextTarget, upwards);
}
- const target = nextContainer?.querySelector<HTMLElement>(projectListActionSelector);
- target?.focus();
+ nextTarget?.focus();
+ }
+
+ private findNextTarget(from:HTMLElement, upwards = false):HTMLElement|null|undefined {
+ let container:Element|null|undefined = from;
+
+ // eslint-disable-next-line no-constant-condition
+ while (true) {
+ if (!container || container.matches(projectListRootSelector)) {
+ return null;
+ }
+
+ const nextNode:Element|null = upwards ? container.previousElementSibling : container.nextElementSibling;
+
+ // If we don't find anything, move up
+ if (!nextNode) {
+ container = container.parentElement;
+ continue;
+ }
+
+ // If we moved to a target, use that
+ if (nextNode?.matches(projectListActionSelector)) {
+ return nextNode as HTMLElement;
+ }
+ // Try to find the next action
+ const targets = nextNode ? Array.from(nextNode.querySelectorAll<HTMLElement>(projectListActionSelector)) : [];
+ const target = upwards ? targets.pop() : targets[0];
+ if (target) {
+ return target;
+ }
+
+ container = nextNode;
+ }
}
onKeydown(event:KeyboardEvent):void {