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

Focus the datepicker banner when switching scheduling mode via the keyboard.

Dombi Attilac47b738dbf1a
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts
index 585c544322e..1d31e91cfde 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts
@@ -309,7 +309,10 @@ export default class PreviewController extends DialogPreviewController {
this.updateFlatpickrCalendar();
}
- afterRendering() {
+ afterRendering(params:{ shouldFocusBanner?:boolean }) {
+ if (params.shouldFocusBanner) {
+ this.focusOnOpen();
+ }
this.readCurrentValues();
this.updateFlatpickrCalendar();
}
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.ts
index fccb75c9dc4..79c1387ff37 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/dialog/preview.controller.ts
@@ -77,7 +77,7 @@ export abstract class DialogPreviewController extends Controller {
const target = event.target as HTMLTurboFrameElement;
const requestUrl = new URL(target.src || '', window.location.origin);
// Do not replace the angular datepicker unless the schedule_manually flag is changed.
- const replaceAngularTags = requestUrl.searchParams.has('schedule_manually');
+ const schedulingChanged = requestUrl.searchParams.has('schedule_manually');
event.detail.render = (currentElement:HTMLElement, newElement:HTMLElement) => {
Idiomorph.morph(currentElement, newElement, {
@@ -87,7 +87,7 @@ export abstract class DialogPreviewController extends Controller {
// In case the element is an OpenProject custom dom element, prevent morphing and
// replace the angular tag with the new version.
if (oldNode.tagName?.startsWith('OPCE-')) {
- if (replaceAngularTags) {
+ if (schedulingChanged) {
oldNode.replaceWith(newNode);
}
return false;
@@ -96,7 +96,7 @@ export abstract class DialogPreviewController extends Controller {
},
},
});
- this.afterRendering();
+ this.afterRendering({ shouldFocusBanner: schedulingChanged });
};
};
@@ -170,7 +170,7 @@ export abstract class DialogPreviewController extends Controller {
}
}
- abstract afterRendering():void;
+ abstract afterRendering(params?:object):void;
// Whether to ignore the active element value when morphing.
abstract ignoreActiveValueWhenMorphing():boolean;
diff --git a/spec/features/a11y/work_packages/datepicker_spec.rb b/spec/features/a11y/work_packages/datepicker_spec.rb
new file mode 100644
index 00000000000..87e6032c44e
--- /dev/null
+++ b/spec/features/a11y/work_packages/datepicker_spec.rb
@@ -0,0 +1,102 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "spec_helper"
+
+RSpec.describe "Datepicker accessibility", :js do
+ let(:project) { create(:project, types: [type]) }
+ let(:type) { create(:type) }
+
+ let(:user) { create(:user, member_with_roles: { project => role }) }
+
+ let!(:parent) do
+ create(:work_package,
+ project:,
+ type:,
+ subject: "Parent",
+ schedule_manually: false)
+ end
+
+ let!(:child) do
+ create(:work_package,
+ project:,
+ parent:,
+ type:,
+ subject: "Child")
+ end
+
+ let!(:wp_table) { Pages::WorkPackagesTable.new(project) }
+ let!(:query) do
+ query = build(:query, user:, project:)
+ query.column_names = %w(subject start_date due_date)
+ query.filters.clear
+ query.show_hierarchies = false
+
+ query.save!
+ query
+ end
+ let(:start_date_field) { wp_table.edit_field(parent, :startDate) }
+ let(:due_date_field) { wp_table.edit_field(parent, :dueDate) }
+ let(:datepicker) { start_date_field.datepicker }
+
+ before do
+ login_as(user)
+
+ wp_table.visit_query query
+ wp_table.expect_work_package_listed parent, child
+ end
+
+ context "with a user allowed to edit dates" do
+ let(:role) { create(:project_role, permissions: %i[view_work_packages edit_work_packages]) }
+
+ it "is accessible" do
+ # Open start date
+ start_date_field.activate!
+ datepicker.expect_visible
+
+ # Expect automatic scheduling
+ datepicker.expect_automatic_scheduling_mode
+
+ # Toggle to manual scheduling mode
+ datepicker.toggle_scheduling_mode_via_keyboard
+
+ # Datepicker banner is focused after switching scheduling to manual mode
+ datepicker.expect_manual_scheduling_mode
+ expect(page).to have_focus_on(".wp-datepicker--banner")
+
+ # Toggle to automatic scheduling mode
+ datepicker.toggle_scheduling_mode_via_keyboard
+
+ # Datepicker banner is focused after switching scheduling to automatic mode
+ datepicker.expect_automatic_scheduling_mode
+ expect(page).to have_focus_on(".wp-datepicker--banner")
+ end
+ end
+end
diff --git a/spec/support/components/datepicker/work_package_datepicker.rb b/spec/support/components/datepicker/work_package_datepicker.rb
index fb8400b1ab4..040f32114e9 100644
--- a/spec/support/components/datepicker/work_package_datepicker.rb
+++ b/spec/support/components/datepicker/work_package_datepicker.rb
@@ -178,6 +178,13 @@ module Components
end
end
+ def toggle_scheduling_mode_via_keyboard
+ page.within_test_selector "op-datepicker-modal--scheduling" do
+ el = page.find('[data-qa-selected="false"]')
+ el.native.send_keys(:enter)
+ end
+ end
+
def click_manual_scheduling_mode
container.click_link I18n.t("work_packages.datepicker_modal.mode.manual")
end