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

Working version of keyboard navigation

Benjamin Bädorf8acb85855c8d
diff --git a/frontend/src/app/shared/components/header-project-select/header-project-select.component.html b/frontend/src/app/shared/components/header-project-select/header-project-select.component.html
index e4ba6238adc..79205637b8c 100644
--- a/frontend/src/app/shared/components/header-project-select/header-project-select.component.html
+++ b/frontend/src/app/shared/components/header-project-select/header-project-select.component.html
@@ -3,6 +3,7 @@
(closed)="close()"
alignment="bottom-left"
class="op-project-list-modal"
+ data-searchable-list-parent="true"
>
<button
id="projects-menu"
@@ -36,7 +37,6 @@
[(ngModel)]="searchableProjectListService.searchText"
[ngModelOptions]="{standalone: true}"
data-qa-selector="op-project-menu-autocomplete--search"
- data-list-focus-catcher-container="true"
data-modal-focus-catcher-container="true"
(keydown)="searchableProjectListService.onKeydown($event, projects)"
>
diff --git a/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts b/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts
index 1c9b23a53e6..40fb57a233c 100644
--- a/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts
+++ b/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts
@@ -145,7 +145,7 @@ export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin {
this.projects$
.pipe(this.untilDestroyed())
.subscribe((projects) => {
- this.searchableProjectListService.resetActiveResult(projects[0].id);
+ this.searchableProjectListService.resetActiveResult(projects[0]?.id);
});
}
diff --git a/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.html b/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.html
index 4d7ad606ab7..4934aecd238 100644
--- a/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.html
+++ b/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.html
@@ -23,7 +23,11 @@
</a>
<span
*ngIf="project.disabled"
- class="spot-list--item-action spot-list--item-action_disabled spot-list--item-action_disabled"
+ [title]="project.name"
+ class="spot-list--item-action spot-list--item-action_disabled"
+ [ngClass]="{
+ 'spot-list--item-action_active': (searchableProjectListService.activeItemID$ | async) === project.id
+ }"
>
<span
class="spot-list--item-title spot-list--item-title_ellipse-text"
diff --git a/frontend/src/app/shared/components/project-include/list/project-include-list.component.html b/frontend/src/app/shared/components/project-include/list/project-include-list.component.html
index c6add4c9717..d0660301050 100644
--- a/frontend/src/app/shared/components/project-include/list/project-include-list.component.html
+++ b/frontend/src/app/shared/components/project-include/list/project-include-list.component.html
@@ -5,20 +5,19 @@
[attr.data-list-selector]="projectListItemIdentifier"
>
<label
- *ngIf="multiSelect"
tabindex="-1"
class="spot-list--item-action op-project-include-list--item-action"
(keydown.space)="changeSelected(project)"
[ngClass]="{
'spot-list--item-action_disabled': isDisabled(project),
- 'spot-list--item-action_active': isActive(project)
+ 'spot-list--item-action_active': (searchableProjectListService.activeItemID$ | async) === project.id
}"
[attr.data-list-selector]="projectListActionIdentifier"
[attr.data-list-disabled]="isDisabled(project) || undefined"
>
<spot-tooltip
class="op-project-include-list--tooltip"
- [alignment]="getAlignment(project, isFirst, isLast)"
+ [alignment]="getTooltipAlignment(project, isFirst, isLast)"
[disabled]="!isDisabled(project)"
[dark]="true"
>
@@ -31,7 +30,7 @@
[attr.data-qa-project-include-checked]="(isChecked(project.href) || (includeSubprojects && parentChecked)) ? 1 : 0"
></spot-checkbox>
<div
- class="spot-list--item-title op-project-include-list--item-title"
+ class="spot-list--item-title spot-list--item-title_ellipsis"
data-qa-selector="op-project-include-list--item-title"
[opSearchHighlight]="searchText"
[title]="project.name"
@@ -49,32 +48,6 @@
</spot-tooltip>
</label>
- <ng-container *ngIf="!multiSelect">
- <a
- *ngIf="!project.disabled"
- class="spot-list--item-action op-project-include-list--item-action"
- [ngClass]="{ 'spot-list--item-action_disabled': project.disabled }"
- [title]="project.name"
- [href]="extendedProjectUrl(project.id)"
- [attr.data-list-selector]="projectListActionIdentifier"
- >
- <span
- class="op-project-include-list--item-title spot-list--item-title"
- data-qa-selector="op-project-include-list--item-title"
- [opSearchHighlight]="searchText"
- >{{ project.name }}</span>
- </a>
- <span
- *ngIf="project.disabled"
- class="spot-list--item-action spot-list--item-action_disabled spot-list--item-action_disabled"
- >
- <span
- class="spot-list--item-title op-project-include-list--item-title"
- data-qa-selector="op-project-include-list--item-disabled-title"
- >{{ project.name }}</span>
- </span>
- </ng-container>
-
<ul
*ngIf="project.children.length"
op-project-include-list
@@ -83,7 +56,6 @@
[includeSubprojects]="includeSubprojects"
[parentChecked]="parentChecked || isChecked(project.href)"
[searchText]="searchText"
- [multiSelect]="multiSelect"
(update)="updateList($event)"
></ul>
</li>
diff --git a/frontend/src/app/shared/components/project-include/list/project-include-list.component.sass b/frontend/src/app/shared/components/project-include/list/project-include-list.component.sass
index 8583f208d83..6d5d9aaaeee 100644
--- a/frontend/src/app/shared/components/project-include/list/project-include-list.component.sass
+++ b/frontend/src/app/shared/components/project-include/list/project-include-list.component.sass
@@ -11,27 +11,5 @@
overflow-y: auto
@include styled-scroll-bar
- &--item-action
- display: flex
-
- &--child-toggle
- opacity: 0
- width: 0
- height: 0
- margin-left: auto
-
- &--item-action:hover &--child-toggle,
- &--child-toggle:focus
- opacity: 1
- width: auto
- height: auto
-
&--tooltip
max-width: 100%
-
- &--item-title
- text-overflow: ellipsis
- white-space: nowrap
- overflow: hidden
- max-width: 100%
- width: 100%
diff --git a/frontend/src/app/shared/components/project-include/list/project-include-list.component.ts b/frontend/src/app/shared/components/project-include/list/project-include-list.component.ts
index e8984f11261..6ec850c851f 100644
--- a/frontend/src/app/shared/components/project-include/list/project-include-list.component.ts
+++ b/frontend/src/app/shared/components/project-include/list/project-include-list.component.ts
@@ -11,6 +11,7 @@ import { CurrentProjectService } from 'core-app/core/current-project/current-pro
import SpotDropAlignmentOption from 'core-app/spot/drop-alignment-options';
import { IProjectData } from 'core-app/shared/components/searchable-project-list/project-data';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
+import { SearchableProjectListService } from 'core-app/shared/components/searchable-project-list/searchable-project-list.service';
@Component({
selector: '[op-project-include-list]',
@@ -37,8 +38,6 @@ export class OpProjectIncludeListComponent {
@Input() parentChecked = false;
- @Input() multiSelect = true;
-
public get currentProjectHref():string|null {
return this.currentProjectService.apiv3Path;
}
@@ -53,6 +52,7 @@ export class OpProjectIncludeListComponent {
readonly I18n:I18nService,
readonly currentProjectService:CurrentProjectService,
readonly pathHelper:PathHelperService,
+ readonly searchableProjectListService:SearchableProjectListService,
) { }
public isDisabled(project:IProjectData):boolean {
@@ -67,7 +67,7 @@ export class OpProjectIncludeListComponent {
return this.includeSubprojects && this.parentChecked;
}
- public updateSelected(selected:string[]):void {
+ public updateList(selected:string[]):void {
this.update.emit(selected);
}
@@ -85,16 +85,16 @@ export class OpProjectIncludeListComponent {
}
if (checked) {
- this.updateSelected(this.selected.filter((selectedHref) => selectedHref !== href));
+ this.updateList(this.selected.filter((selectedHref) => selectedHref !== href));
} else {
- this.updateSelected([
+ this.updateList([
...this.selected,
href,
]);
}
}
- public getAlignment(project:IProjectData, isFirst:boolean, isLast:boolean):SpotDropAlignmentOption {
+ public getTooltipAlignment(project:IProjectData, isFirst:boolean, isLast:boolean):SpotDropAlignmentOption {
if (!this.root || !isFirst) {
return SpotDropAlignmentOption.TopLeft;
}
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 bef4c3f8694..91bdb2834d5 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
@@ -3,6 +3,7 @@
alignment="bottom-right"
(closed)="opened = false"
class="op-project-list-modal"
+ data-searchable-list-parent="true"
>
<button
slot="trigger"
@@ -31,6 +32,7 @@
<form
(submit)="onSubmit($event)"
class="spot-container op-project-list-modal--body"
+ *ngIf="projects$ | async as projects"
>
<spot-text-field
[placeholder]="text.search_placeholder"
@@ -40,7 +42,7 @@
data-qa-selector="project-include-search"
data-list-focus-catcher-container="true"
data-modal-focus-catcher-container="true"
- (keydown)="searchableProjectListService.onKeydown($event)"
+ (keydown)="searchableProjectListService.onKeydown($event, projects)"
>
<span
slot="before"
@@ -49,27 +51,25 @@
</spot-text-field>
<ng-container *ngIf="(loading$ | async) === false; else loadingTemplate">
- <ng-container *ngIf="(projects$ | async) as projects">
- <ul
- *ngIf="projects.length > 0; else noResultsTemplate"
- class="op-project-include--list"
- op-project-list
- [projects]="projects"
- [selected]="selectedProjects"
- [includeSubprojects]="includeSubprojects$ | async"
- [searchText]="searchableProjectListService.searchText"
- [root]="true"
- (update)="selectedProjects = $event"
- data-qa-selector="project-include-list"
- data-list-root="true"
- ></ul>
+ <ul
+ *ngIf="projects.length > 0; else noResultsTemplate"
+ class="op-project-include--list"
+ op-project-include-list
+ [projects]="projects"
+ [selected]="selectedProjects"
+ [includeSubprojects]="includeSubprojects$ | async"
+ [searchText]="searchableProjectListService.searchText"
+ [root]="true"
+ (update)="selectedProjects = $event"
+ data-qa-selector="project-include-list"
+ data-list-root="true"
+ ></ul>
- <ng-template #noResultsTemplate>
- <span class="op-project-list-modal--no-results">
- {{text.no_results}}
- </span>
- </ng-template>
- </ng-container>
+ <ng-template #noResultsTemplate>
+ <span class="op-project-list-modal--no-results">
+ {{text.no_results}}
+ </span>
+ </ng-template>
</ng-container>
<div class="spot-action-bar">
@@ -104,37 +104,9 @@
</ng-container>
<ng-template #loadingTemplate>
- <op-content-loader
+ <op-loading-project-list
class="op-project-list-modal--loading"
data-qa-selector="op-project-include--loading"
- viewBox="0 0 200 140"
- >
- <svg:rect x="0" width="12" height="12" rx="1" />
- <svg:rect x="15" width="100%" height="12" rx="1" />
-
- <svg:rect x="10" y="16" width="12" height="12" rx="1" />
- <svg:rect x="25" y="16" width="100%" height="12" rx="1" />
-
- <svg:rect x="10" y="32" width="12" height="12" rx="1" />
- <svg:rect x="25" y="32" width="100%" height="12" rx="1" />
-
- <svg:rect x="20" y="48" width="12" height="12" rx="1" />
- <svg:rect x="35" y="48" width="100%" height="12" rx="1" />
-
- <svg:rect x="20" y="64" width="12" height="12" rx="1" />
- <svg:rect x="35" y="64" width="100%" height="12" rx="1" />
-
- <svg:rect x="0" y="80" width="12" height="12" rx="1" />
- <svg:rect x="15" y="80" width="100%" height="12" rx="1" />
-
- <svg:rect x="10" y="96" width="12" height="12" rx="1" />
- <svg:rect x="25" y="96" width="100%" height="12" rx="1" />
-
- <svg:rect x="10" y="112" width="12" height="12" rx="1" />
- <svg:rect x="25" y="112" width="100%" height="12" rx="1" />
-
- <svg:rect x="0" y="128" width="12" height="12" rx="1" />
- <svg:rect x="15" y="128" width="100%" height="12" rx="1" />
- </op-content-loader>
+ ></op-loading-project-list>
</ng-template>
</spot-drop-modal>
diff --git a/frontend/src/app/shared/components/project-include/project-include.component.ts b/frontend/src/app/shared/components/project-include/project-include.component.ts
index f15ab7f1249..0bf68fc9bc7 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
@@ -210,6 +210,12 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
readonly searchableProjectListService:SearchableProjectListService,
) {
super();
+
+ this.projects$
+ .pipe(this.untilDestroyed())
+ .subscribe((projects) => {
+ this.searchableProjectListService.resetActiveResult(projects[0]?.id);
+ });
}
public ngOnInit():void {
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 a84f44bacf3..6c171aedf0d 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
@@ -93,8 +93,9 @@ export class SearchableProjectListService {
this.selectNextResult(activeID, projects);
break;
case KeyCodes.ENTER:
+ event.stopPropagation();
event.preventDefault();
- this.activateSelectedResult(activeID, projects);
+ this.activateSelectedResult(event);
break;
}
});
@@ -105,10 +106,18 @@ export class SearchableProjectListService {
}
private selectPreviousResult(id:ID, projects:IProjectData[]) {
+ const findLastChild = (project:IProjectData):IProjectData => {
+ if (project?.children?.length) {
+ return findLastChild(project.children[project.children.length - 1]);
+ }
+
+ return project;
+ };
+
const findPreviousID = (projects:IProjectData[], parent?:IProjectData):ID|null => {
for (let i = 0; i < projects.length; i++) {
if (projects[i].id === id) {
- const previous = projects[i - 1] || parent;
+ const previous = findLastChild(projects[i - 1]) || projects[i - 1] || parent;
return previous?.id || null;
}
@@ -117,30 +126,51 @@ export class SearchableProjectListService {
return previous;
}
}
- }
+
+ return null;
+ };
const foundPreviousID = findPreviousID(projects);
this.activeItemID$.next(foundPreviousID || projects[0]?.id || 0);
}
private selectNextResult(id:ID, projects:IProjectData[]) {
- const findNextID = (projects:IProjectData[], previousParent?:IProjectData):ID|null => {
- for (let i = projects.length - 1; i >= 0; i--) {
+ const findNextID = (projects:IProjectData[], nextParent?:IProjectData):ID|null => {
+ for (let i = 0; i < projects.length; i++) {
if (projects[i].id === id) {
- const next = projects[i + 1] || parent;
+ const next = projects[i].children[0] || projects[i + 1] || nextParent;
return next?.id || null;
}
- const previous = findNextID(projects[i].children, projects[i]);
- if (previous !== null) {
- return previous;
+ const next = findNextID(projects[i].children, projects[i + 1] || nextParent);
+ if (next !== null) {
+ return next;
}
}
+
+ return null;
}
const foundNextID = findNextID(projects);
this.activeItemID$.next(foundNextID || projects[0]?.id || 0);
}
- private activateSelectedResult() {
+
+ private activateSelectedResult(event:KeyboardEvent) {
+ const findSearchableListParent = (el:HTMLElement|null):HTMLElement|null => {
+ if (!el) {
+ return null;
+ }
+
+ if ("searchableListParent" in el.dataset) {
+ return el;
+ }
+
+ return findSearchableListParent(el.parentElement);
+ };
+
+ const listParent = findSearchableListParent(event.currentTarget as HTMLElement);
+ const focused = document.activeElement;
+ (listParent?.querySelector('.spot-list--item-action_active') as HTMLElement)?.click();
+ (focused as HTMLElement)?.focus();
}
}
diff --git a/frontend/src/app/spot/styles/sass/components/list.sass b/frontend/src/app/spot/styles/sass/components/list.sass
index ad809981532..ee8684d155f 100644
--- a/frontend/src/app/spot/styles/sass/components/list.sass
+++ b/frontend/src/app/spot/styles/sass/components/list.sass
@@ -27,20 +27,26 @@
> *:first-child
flex-shrink: 0
+ &:focus
+ @include spot-focus
+
&_active,
&:hover
color: var(--content-link-hover-active-color)
background-color: $spot-color-basic-gray-6
-
- &:focus
- @include spot-focus
+ text-decoration: none
&_disabled
&,
&:hover
color: $spot-color-basic-gray-3
+ background-color: transparent
cursor: default
+ &_active#{&}_disabled
+ color: $spot-color-basic-gray-3
+ background-color: $spot-color-basic-gray-6
+
&_link
color: var(--content-link-color)