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

Add some accessibility attributes to context menus

Christophe Bliard8177cce8f165
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index ad27e8e0dd8..20b0cf25285 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -566,6 +566,7 @@ en:
label_watcher_added_successfully: "Watcher successfully added!"
label_watcher_deleted_successfully: "Watcher successfully deleted!"
label_work_package_details_you_are_here: "You are on the %{tab} tab for %{type} %{subject}."
+ label_work_package_context_menu: "Work package context menu"
label_unwatch: "Unwatch"
label_unwatch_work_package: "Unwatch work package"
label_uploaded_by: "Uploaded by"
diff --git a/frontend/src/app/shared/components/op-context-menu/op-context-menu.html b/frontend/src/app/shared/components/op-context-menu/op-context-menu.html
index c3ae85a5cdc..34b2fb6b46e 100644
--- a/frontend/src/app/shared/components/op-context-menu/op-context-menu.html
+++ b/frontend/src/app/shared/components/op-context-menu/op-context-menu.html
@@ -3,13 +3,15 @@
ng-class="{'dropdown-anchor-right': locals.showAnchorRight}">
<ul class="dropdown-menu "
role="menu"
+ [attr.aria-label]="locals.label"
[ngClass]="{'-empty': items.length === 0 }">
<ng-container *ngFor="let item of items">
- <li *ngIf="item.divider" class="dropdown-divider"></li>
+ <li *ngIf="item.divider" class="dropdown-divider" role="separator"></li>
<li *ngIf="!item.divider">
<a
*ngIf="item.href"
class="menu-item"
+ role="menuitem"
[ngClass]="item.class"
[class.inactive]="item.disabled"
[attr.href]="item.href"
@@ -27,6 +29,7 @@
<button
*ngIf="!item.href"
class="menu-item"
+ role="menuitem"
[ngClass]="item.class"
[class.inactive]="item.disabled"
[attr.aria-disabled]="item.disabled"
diff --git a/frontend/src/app/shared/components/op-context-menu/op-context-menu.types.ts b/frontend/src/app/shared/components/op-context-menu/op-context-menu.types.ts
index eae70a6d992..17f42c82b6d 100644
--- a/frontend/src/app/shared/components/op-context-menu/op-context-menu.types.ts
+++ b/frontend/src/app/shared/components/op-context-menu/op-context-menu.types.ts
@@ -2,12 +2,6 @@ import { InjectionToken } from '@angular/core';
export const OpContextMenuLocalsToken = new InjectionToken<any>('CONTEXT_MENU_LOCALS');
-export interface OpContextMenuLocalsMap {
- items:OpContextMenuItem[];
- contextMenuId?:string;
- [key:string]:any;
-}
-
export interface OpContextMenuItem {
disabled?:boolean;
hidden?:boolean;
@@ -20,3 +14,12 @@ export interface OpContextMenuItem {
divider?:boolean;
onClick?:($event:JQuery.TriggeredEvent|MouseEvent) => boolean;
}
+
+export interface OpContextMenuLocalsMap {
+ items:OpContextMenuItem[];
+ showAnchorRight?:boolean;
+ contextMenuId?:string;
+ label?:string;
+ /* eslint-disable @typescript-eslint/no-explicit-any */
+ [key:string]:any;
+}
diff --git a/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.ts b/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.ts
index ffa2dec3f56..2ab580489ec 100644
--- a/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.ts
+++ b/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.ts
@@ -59,17 +59,23 @@ export class WorkPackageViewContextMenu extends OpContextMenuHandler {
private copyToClipboardService:CopyToClipboardService;
- constructor(public injector:Injector,
+ constructor(
+ public injector:Injector,
protected workPackageId:string,
protected $element:JQuery,
protected additionalPositionArgs:any = {},
- protected allowSplitScreenActions:boolean = true) {
+ protected allowSplitScreenActions:boolean = true,
+ ) {
super(injector.get(OPContextMenuService));
this.copyToClipboardService = injector.get(CopyToClipboardService);
}
public get locals():OpContextMenuLocalsMap {
- return { contextMenuId: 'work-package-context-menu', items: this.items };
+ return {
+ contextMenuId: 'work-package-context-menu',
+ label: I18n.t('js.label_work_package_context_menu'),
+ items: this.items,
+ };
}
public positionArgs(evt:JQuery.TriggeredEvent) {
diff --git a/spec/features/work_packages/bulk/copy_work_package_spec.rb b/spec/features/work_packages/bulk/copy_work_package_spec.rb
index fd9f238613d..c2e036b4fd2 100644
--- a/spec/features/work_packages/bulk/copy_work_package_spec.rb
+++ b/spec/features/work_packages/bulk/copy_work_package_spec.rb
@@ -303,7 +303,7 @@ RSpec.describe 'Copy work packages through Rails view', :js, :with_cuprite do
it 'does allow to copy' do
context_menu.open_for work_package
- context_menu.expect_options ['Bulk copy']
+ context_menu.expect_options 'Bulk copy'
end
end
@@ -312,7 +312,8 @@ RSpec.describe 'Copy work packages through Rails view', :js, :with_cuprite do
it 'does not allow to copy' do
context_menu.open_for work_package
- context_menu.expect_no_options ['Bulk copy']
+ $stop = true
+ context_menu.expect_no_options 'Bulk copy'
end
end
end
diff --git a/spec/features/work_packages/bulk/move_work_package_spec.rb b/spec/features/work_packages/bulk/move_work_package_spec.rb
index 881fefb192e..c3bf0b8b312 100644
--- a/spec/features/work_packages/bulk/move_work_package_spec.rb
+++ b/spec/features/work_packages/bulk/move_work_package_spec.rb
@@ -255,7 +255,7 @@ RSpec.describe 'Moving a work package through Rails view', :js do
context 'with permissions' do
it 'does allow to move' do
context_menu.open_for work_package
- context_menu.expect_options ['Bulk change of project']
+ context_menu.expect_options 'Bulk change of project'
end
end
@@ -264,7 +264,7 @@ RSpec.describe 'Moving a work package through Rails view', :js do
it 'does not allow to move' do
context_menu.open_for work_package
- context_menu.expect_no_options ['Bulk change of project']
+ context_menu.expect_no_options 'Bulk change of project'
end
end
end
diff --git a/spec/features/work_packages/bulk/update_work_package_spec.rb b/spec/features/work_packages/bulk/update_work_package_spec.rb
index 0b5392c67cf..7d4c611e634 100644
--- a/spec/features/work_packages/bulk/update_work_package_spec.rb
+++ b/spec/features/work_packages/bulk/update_work_package_spec.rb
@@ -220,7 +220,7 @@ RSpec.describe 'Bulk update work packages through Rails view', :js, :with_cuprit
it 'does allow to edit' do
context_menu.open_for work_package
- context_menu.expect_options ['Bulk edit']
+ context_menu.expect_options 'Bulk edit'
end
context 'with a project budget' do
@@ -243,7 +243,7 @@ RSpec.describe 'Bulk update work packages through Rails view', :js, :with_cuprit
it 'does not allow to edit' do
context_menu.open_for work_package
- context_menu.expect_no_options ['Bulk edit']
+ context_menu.expect_no_options 'Bulk edit'
end
end
end
diff --git a/spec/features/work_packages/table/context_menu/context_menu_spec.rb b/spec/features/work_packages/table/context_menu/context_menu_spec.rb
index 472213a20b7..6fefc826a03 100644
--- a/spec/features/work_packages/table/context_menu/context_menu_spec.rb
+++ b/spec/features/work_packages/table/context_menu/context_menu_spec.rb
@@ -39,7 +39,7 @@ RSpec.describe 'Work package table context menu', :js, :with_cuprite do
# Open context menu
menu.expect_closed
menu.open_for(work_package)
- menu.expect_options ['Add predecessor', 'Add follower']
+ menu.expect_options 'Add predecessor', 'Add follower'
end
context 'for multiple selected WPs' do
@@ -57,8 +57,8 @@ RSpec.describe 'Work package table context menu', :js, :with_cuprite do
find('body').send_keys [:control, 'a']
menu.open_for(work_package)
- menu.expect_options ['Open details view', 'Open fullscreen view',
- 'Bulk edit', 'Bulk copy', 'Bulk change of project', 'Bulk delete']
+ menu.expect_options 'Open details view', 'Open fullscreen view',
+ 'Bulk edit', 'Bulk copy', 'Bulk change of project', 'Bulk delete'
end
end
end
diff --git a/spec/support/components/work_packages/context_menu.rb b/spec/support/components/work_packages/context_menu.rb
index a520e6965cc..58f5eaa2388 100644
--- a/spec/support/components/work_packages/context_menu.rb
+++ b/spec/support/components/work_packages/context_menu.rb
@@ -61,15 +61,17 @@ module Components
end
def expect_open
- expect(page).to have_selector(selector)
+ expect(page).to have_selector(:menu, work_package_context_menu_label)
end
def expect_closed
- expect(page).to have_no_selector(selector)
+ expect(page).to have_no_selector(:menu, work_package_context_menu_label)
end
def choose(target)
- find("#{selector} .menu-item", text: target, exact_text: true).click
+ within_menu do
+ find(:menuitem, text: target, exact_text: true).click
+ end
end
def choose_delete_and_confirm_deletion
@@ -83,22 +85,30 @@ module Components
def expect_no_options(*options)
expect_open
- options.each do |text|
- expect(page).to have_no_css("#{selector} .menu-item", text:)
+ within_menu do
+ options.each do |text|
+ expect(page).to have_no_selector(:menuitem, text:)
+ end
end
end
- def expect_options(options)
+ def expect_options(*options)
expect_open
- options.each do |text|
- expect(page).to have_css("#{selector} .menu-item", text:)
+ within_menu do
+ options.each do |text|
+ expect(page).to have_selector(:menuitem, text:)
+ end
end
end
private
- def selector
- '#work-package-context-menu'
+ def within_menu(&)
+ within(:menu, work_package_context_menu_label, &)
+ end
+
+ def work_package_context_menu_label
+ I18n.t('js.label_work_package_context_menu')
end
end
end
diff --git a/spec/support/components/work_packages/hierarchies.rb b/spec/support/components/work_packages/hierarchies.rb
index 2dffe645368..1f9175abdab 100644
--- a/spec/support/components/work_packages/hierarchies.rb
+++ b/spec/support/components/work_packages/hierarchies.rb
@@ -79,11 +79,11 @@ module Components
context_menu.open_for work_package
if indent
- context_menu.expect_options ['Indent hierarchy']
+ context_menu.expect_options 'Indent hierarchy'
end
if outdent
- context_menu.expect_options ['Outdent hierarchy']
+ context_menu.expect_options 'Outdent hierarchy'
end
end
diff --git a/spec/support/components/work_packages/settings_menu.rb b/spec/support/components/work_packages/settings_menu.rb
index 409201ef8da..924fedffdb9 100644
--- a/spec/support/components/work_packages/settings_menu.rb
+++ b/spec/support/components/work_packages/settings_menu.rb
@@ -74,7 +74,7 @@ module Components
find("#{selector} .menu-item", text: target, match: :prefer_exact).click
end
- def expect_options(options)
+ def expect_options(*options)
expect_open
options.each do |text|
expect(page).to have_css("#{selector} a", text:)