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
Properly focus duration when opening from the wp table
Benjamin Bädorf9ec00019e14c
diff --git a/frontend/src/app/shared/components/datepicker/multi-date-picker/multi-date-picker.component.html b/frontend/src/app/shared/components/datepicker/multi-date-picker/multi-date-picker.component.htmlindex 56f52206460..68c235d5fa5 100644--- a/frontend/src/app/shared/components/datepicker/multi-date-picker/multi-date-picker.component.html+++ b/frontend/src/app/shared/components/datepicker/multi-date-picker/multi-date-picker.component.html@@ -80,7 +80,10 @@</spot-form-field></div>- <div #flatpickrTarget></div>+ <input+ id="flatpickr-input"+ #flatpickrTarget+ hidden><div class="spot-action-bar"><div class="spot-action-bar--right">diff --git a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.html b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.htmlindex f239678dbea..e6f18970641 100644--- a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.html+++ b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.html@@ -104,8 +104,10 @@</spot-form-field></div>- <input id="flatpickr-input"- hidden>+ <input+ id="flatpickr-input"+ #flatpickrTarget+ hidden></div><div class="spot-action-bar">diff --git a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.ts b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.tsindex 9ce345eafed..9a5a9965acd 100644--- a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.ts+++ b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.ts@@ -121,6 +121,8 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements A@ViewChild('durationField', { read: ElementRef }) durationField:ElementRef<HTMLElement>;+ @ViewChild('flatpickrTarget') flatpickrTarget:ElementRef;+@Input() changeset:ResourceChangeset;@Input() fieldName:string = '';@@ -281,17 +283,20 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements A}ngAfterViewInit():void {+ console.log('ngAfterViewInit');this.dateModalRelations.getMinimalDateFromPreceeding().subscribe((date) => {+ console.log('initialize date picker');this.initializeDatepicker(date);- });- // Autofocus duration if that's what activated us- if (this.initialActivatedField === 'duration') {- this.focusHelper.focus(this.durationField.nativeElement);- }+ // Autofocus duration if that's what activated us+ if (this.initialActivatedField === 'duration') {+ console.log('focus duration');+ this.focusHelper.focus(this.durationField.nativeElement);+ }+ });}changeSchedulingMode():void {@@ -498,7 +503,7 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements A);},},- null,+ this.flatpickrTarget.nativeElement,);}diff --git a/frontend/src/app/shared/directives/focus/focus-helper.ts b/frontend/src/app/shared/directives/focus/focus-helper.tsindex e1ef88ba135..e0108d5e112 100644--- a/frontend/src/app/shared/directives/focus/focus-helper.ts+++ b/frontend/src/app/shared/directives/focus/focus-helper.ts@@ -27,31 +27,15 @@//++import { Injectable } from '@angular/core';+import { findAllFocusableElementsWithin } from 'core-app/shared/helpers/focus-helpers';@Injectable({ providedIn: 'root' })export class FocusHelperService {- private static FOCUSABLE_SELECTORS = 'a, button, input, [tabindex], select, textarea';-- public getFocusableElement(element:HTMLElement):HTMLElement {- const focusser = element.querySelector<HTMLElement>('input.ui-select-focusser');-- if (focusser) {- return focusser;- }-- let focusable = element;-- if (!element.matches(FocusHelperService.FOCUSABLE_SELECTORS)) {- focusable = element.querySelector<HTMLElement>(FocusHelperService.FOCUSABLE_SELECTORS) || element;- }-- return focusable;- }-public focus(element:HTMLElement):void {setTimeout(() => {- const focusable = this.getFocusableElement(element);+ const focusable = findAllFocusableElementsWithin(element)[0];+ console.log('focus', focusable);focusable?.focus();- }, 10);+ }, 20);}}diff --git a/frontend/src/app/shared/helpers/focus-helpers.ts b/frontend/src/app/shared/helpers/focus-helpers.tsindex b96f98dbe4c..791e0e88c0a 100644--- a/frontend/src/app/shared/helpers/focus-helpers.ts+++ b/frontend/src/app/shared/helpers/focus-helpers.ts@@ -1,7 +1,7 @@/*** Elements that can receive focus*/-const focusableElements = [+export const FOCUSABLE_ELEMENT_SELECTORS = ['a[href]:not([tabindex^="-"])','area[href]:not([tabindex^="-"])','input:not([type="hidden"]):not([type="radio"]):not([disabled]):not([tabindex^="-"])',@@ -19,6 +19,6 @@ const focusableElements = [/*** Find all focusable element within a given container*/-export function findAllFocusableElementsWithin(container:HTMLElement):NodeListOf<Element> {- return container.querySelectorAll(focusableElements.toString());+export function findAllFocusableElementsWithin(container:HTMLElement):NodeListOf<HTMLElement> {+ return container.querySelectorAll(FOCUSABLE_ELEMENT_SELECTORS.toString());}diff --git a/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts b/frontend/src/app/spot/components/drop-modal/drop-modal.component.tsindex 2ce22a97a24..9df47b1c176 100644--- a/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts+++ b/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts@@ -85,6 +85,11 @@ export class SpotDropModalComponent implements OnDestroy {this.recalculateAlignment();}+ // If we already have focus within the modal, don't move it+ if (this.elementRef.nativeElement.contains(document.activeElement)) {+ return;+ }+const focusCatcherContainer = document.querySelectorAll("[data-modal-focus-catcher-container='true']")[0];if (focusCatcherContainer) {(findAllFocusableElementsWithin(focusCatcherContainer as HTMLElement)[0] as HTMLElement).focus();diff --git a/spec/features/work_packages/table/duration_field_spec.rb b/spec/features/work_packages/table/duration_field_spec.rbindex fcc010644c4..a3eaab536ba 100644--- a/spec/features/work_packages/table/duration_field_spec.rb+++ b/spec/features/work_packages/table/duration_field_spec.rb@@ -37,7 +37,6 @@ describe 'Duration field in the work package table',duration.expect_state_text '4 days'duration.activate!- byebugdate_field.expect_duration_highlightedexpect(page).to have_focus_on('[data-qa-selector="op-datepicker-modal--duration-field"] input[name="duration"]')expect(page).to have_field('duration', with: '4', wait: 10)