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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Move without keeping an index of the list
Oliver Günther09a0e67c36e9
diff --git a/frontend/src/app/shared/components/autocompleter/project-menu-autocomplete/project-menu-autocomplete.component.ts b/frontend/src/app/shared/components/autocompleter/project-menu-autocomplete/project-menu-autocomplete.component.tsindex 13394fd70fa..985586362a9 100644--- a/frontend/src/app/shared/components/autocompleter/project-menu-autocomplete/project-menu-autocomplete.component.ts+++ b/frontend/src/app/shared/components/autocompleter/project-menu-autocomplete/project-menu-autocomplete.component.ts@@ -137,14 +137,12 @@ export class ProjectMenuAutocompleteComponent {this.dropModalOpen = !this.dropModalOpen;if (this.dropModalOpen) {this.searchableProjectListService.loadAllProjects();- this.searchableProjectListService.registerArrowNavigationOnItems();}}close():void {this.searchableProjectListService.searchText = '';this.dropModalOpen = false;- this.searchableProjectListService.destroyArrowNavigation();}currentProjectName():string {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.htmlindex 7448a0befb5..3f35817b2cc 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@@ -1,6 +1,7 @@<spot-drop-modal[open]="dropModalOpen"(closed)="close()"+ (keydown)="searchableProjectListService.onKeydown($event)"alignment="bottom-left"class="op-project-list-modal">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.htmlindex f8211d4c677..fef996953b0 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@@ -2,6 +2,7 @@[open]="opened"alignment="bottom-right"(closed)="opened = false"+ (keydown)="searchableProjectListService.onKeydown($event)"class="op-project-list-modal"><buttondiff --git a/frontend/src/app/shared/components/project-include/project-include.component.ts b/frontend/src/app/shared/components/project-include/project-include.component.tsindex 4a751c31ec0..56d740f5314 100644--- a/frontend/src/app/shared/components/project-include/project-include.component.ts+++ b/frontend/src/app/shared/components/project-include/project-include.component.ts@@ -231,7 +231,6 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements Onif (this.opened) {this.searchableProjectListService.loadAllProjects();- this.searchableProjectListService.registerArrowNavigationOnItems();this.projectsInFilter$.pipe(take(1),@@ -265,6 +264,5 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements Onpublic close():void {this.opened = false;- this.searchableProjectListService.destroyArrowNavigation();}}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.htmlindex 95b411ffd9d..1d225152a04 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@@ -7,7 +7,7 @@*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]="projectListActionSelector"+ [attr.data-list-action-selector]="projectListActionIdentifier"><spot-tooltipclass="op-project-list--tooltip"@@ -50,7 +50,7 @@[ngClass]="{ 'spot-list--item-action_disabled': project.disabled }"[title]="project.name"[href]="extendedProjectUrl(project.id)"- [attr.data-list-action-selector]="projectListActionSelector"+ [attr.data-list-action-selector]="projectListActionIdentifier"><spanclass="op-project-list--item-title spot-list--item-title"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.tsindex 550fba8c410..41a5af7931d 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,7 +12,8 @@ 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 projectListActionSelector = 'op-project-list--item-action';+export const projectListActionIdentifier:string = 'op-project-list--item-action';+export const projectListActionSelector:string = `[data-list-action-selector='${projectListActionIdentifier}']`;@Component({selector: '[op-project-list]',@@ -51,7 +52,7 @@ export class OpProjectListComponent {current_project: this.I18n.t('js.include_projects.tooltip.current_project'),};- projectListActionSelector = projectListActionSelector;+ projectListActionIdentifier = projectListActionIdentifier;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.tsindex 4debe8411bc..c48dc81e974 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@@ -76,29 +76,47 @@ export class SearchableProjectListService {};}- registerArrowNavigationOnItems():void {- let currentIndex = -1;-- document.addEventListener('keydown', (event) => {- // Todo: Instead of collecting the items every time, do it once at the beginning.- // Keep in mind that the list needs to be loaded first, and the list might change when searched- const items = document.querySelectorAll(`[data-list-action-selector='${projectListActionSelector}']`);-- if (event.keyCode === KeyCodes.UP_ARROW) {- // Decrease the counter- currentIndex = currentIndex > 0 ? currentIndex -= 1 : 0;- } else if (event.keyCode === KeyCodes.DOWN_ARROW) {- // Increase counter- currentIndex = currentIndex < items.length - 1 ? currentIndex += 1 : items.length - 1;- } else {- return;- }-- (items[currentIndex] as HTMLElement).focus();- });+ 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)) {+ this.moveFocus(focused, upwards);+ return;+ }++ // If we're moving down, select first+ if (!upwards) {+ const first = document.querySelector<HTMLElement>(projectListActionSelector);+ first?.focus();+ }}- destroyArrowNavigation():void {- // Todo: Implement+ private moveFocus(source:Element, upwards = false):void {+ const activeItem = source.closest(projectListActionSelector) as HTMLElement;+ let nextContainer:Element|null|undefined;++ if (upwards) {+ nextContainer = activeItem.previousElementSibling || activeItem.closest('li')?.previousElementSibling;+ } else {+ nextContainer = activeItem?.nextElementSibling || activeItem.closest('li')?.nextElementSibling;+ }++ const target = nextContainer?.querySelector<HTMLElement>(projectListActionSelector);+ target?.focus();+ }++ onKeydown(event:KeyboardEvent):void {+ switch (event.keyCode) {+ case KeyCodes.UP_ARROW:+ this.handleKeyNavigation(true);+ break;+ case KeyCodes.DOWN_ARROW:+ this.handleKeyNavigation(false);+ break;+ default:+ break;+ }}}