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
[#61916] Autofocus on text fields
Mir Bhatia97bc012ee7e7
diff --git a/frontend/src/stimulus/controllers/dynamic/meeting-outcome-form.controller.ts b/frontend/src/stimulus/controllers/ckeditor-focus.controller.tssimilarity index 67%rename from frontend/src/stimulus/controllers/dynamic/meeting-outcome-form.controller.tsrename to frontend/src/stimulus/controllers/ckeditor-focus.controller.tsindex 79b76e85d46..c9c3e0c8e27 100644--- a/frontend/src/stimulus/controllers/dynamic/meeting-outcome-form.controller.ts+++ b/frontend/src/stimulus/controllers/ckeditor-focus.controller.ts@@ -29,13 +29,31 @@*/import { Controller } from '@hotwired/stimulus';+import { ICKEditorInstance } from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';export default class extends Controller {+ static values = { autofocus: Boolean };+ declare autofocusValue:boolean;++ static targets = ['editor'];+ declare readonly editorTarget:HTMLElement;+connect():void {- this.focusInput();+ if (this.autofocusValue) {+ this.focusInput();+ }}focusInput():void {this.element.scrollIntoView({ block: 'center' });++ const ckeditorField = this.editorTarget.querySelector('op-ckeditor') as HTMLElement;+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call+ void jQuery(ckeditorField)+ .data('editor')+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access+ .then((editor:ICKEditorInstance) => {+ editor.editing.view.focus();+ });}}diff --git a/frontend/src/stimulus/controllers/dynamic/meeting-agenda-item-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/meeting-agenda-item-form.controller.tsindex 17adf57c017..b17463a70da 100644--- a/frontend/src/stimulus/controllers/dynamic/meeting-agenda-item-form.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/meeting-agenda-item-form.controller.ts@@ -34,14 +34,14 @@ import { Controller } from '@hotwired/stimulus';export default class extends Controller {static values = {cancelUrl: String,+ autofocus: Boolean,};declare cancelUrlValue:string;+ declare autofocusValue:boolean;- static targets = ['titleInput', 'notesInput', 'notesAddButton'];- declare readonly titleInputTarget:HTMLInputElement;+ static targets = ['notesInput'];declare readonly notesInputTarget:HTMLInputElement;- declare readonly notesAddButtonTarget:HTMLInputElement;connect():void {this.focusInput();@@ -52,7 +52,7 @@ export default class extends Controller {const titleInput = this.element.querySelector('input[name="meeting_agenda_item[title]"]');this.element.scrollIntoView({ block: 'center' });- if (titleInput) {+ if (titleInput && this.autofocusValue) {(titleInput as HTMLInputElement).focus();this.setCursorAtEnd(titleInput as HTMLInputElement);}diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.tsindex 23e1d7e13d1..1fd221488df 100644--- a/frontend/src/stimulus/setup.ts+++ b/frontend/src/stimulus/setup.ts@@ -18,6 +18,7 @@ import PreviewController from './controllers/dynamic/work-packages/date-picker/pimport KeepScrollPositionController from './controllers/keep-scroll-position.controller';import PatternInputController from './controllers/pattern-input.controller';import HoverCardTriggerController from './controllers/hover-card-trigger.controller';+import CkeditorFocusController from './controllers/ckeditor-focus.controller';declare global {interface Window {@@ -51,3 +52,4 @@ instance.register('projects-zen-mode', OpProjectsZenModeController);instance.register('work-packages--date-picker--preview', PreviewController);instance.register('keep-scroll-position', KeepScrollPositionController);instance.register('pattern-input', PatternInputController);+instance.register('ckeditor-focus', CkeditorFocusController);diff --git a/modules/meeting/app/components/meeting_agenda_items/form_component.html.erb b/modules/meeting/app/components/meeting_agenda_items/form_component.html.erbindex fdf965b49a6..fe405d7c7ed 100644--- a/modules/meeting/app/components/meeting_agenda_items/form_component.html.erb+++ b/modules/meeting/app/components/meeting_agenda_items/form_component.html.erb@@ -11,7 +11,7 @@when :simplerender(MeetingAgendaItem::Title.new(f))when :work_package- render(MeetingAgendaItem::WorkPackage.new(f))+ render(MeetingAgendaItem::WorkPackage.new(f, autofocus: @autofocus))endenddiff --git a/modules/meeting/app/components/meeting_agenda_items/form_component.rb b/modules/meeting/app/components/meeting_agenda_items/form_component.rbindex 64e8578a9c8..5bffbbd5300 100644--- a/modules/meeting/app/components/meeting_agenda_items/form_component.rb+++ b/modules/meeting/app/components/meeting_agenda_items/form_component.rb@@ -36,7 +36,6 @@ module MeetingAgendaItemsdef initialize(meeting:, meeting_section:, meeting_agenda_item:, method:, submit_path:, cancel_path:, type: :simple,display_notes_input: nil)super-@meeting = meeting@meeting_section = meeting_section@meeting_agenda_item = meeting_agenda_item@@ -45,6 +44,7 @@ module MeetingAgendaItems@cancel_path = cancel_path@type = type@display_notes_input = display_notes_input+ @autofocus = display_notes_input.blank?enddef wrapper_uniq_by@@ -59,9 +59,12 @@ module MeetingAgendaItemsdef wrapper_data_attributes{- controller: "meeting-agenda-item-form",+ controller: "meeting-agenda-item-form ckeditor-focus","application-target": "dynamic",- "meeting-agenda-item-form-cancel-url-value": @cancel_path+ "meeting-agenda-item-form-cancel-url-value": @cancel_path,+ "meeting-agenda-item-form-autofocus-value": @autofocus,+ "ckeditor-focus-target": "editor",+ "ckeditor-focus-autofocus-value": !@autofocus}enddiff --git a/modules/meeting/app/components/meeting_agenda_items/outcomes/form_component.html.erb b/modules/meeting/app/components/meeting_agenda_items/outcomes/form_component.html.erbindex 26c7cd642d8..6c738476ba6 100644--- a/modules/meeting/app/components/meeting_agenda_items/outcomes/form_component.html.erb+++ b/modules/meeting/app/components/meeting_agenda_items/outcomes/form_component.html.erb@@ -1,5 +1,5 @@<%=- component_wrapper(data: wrapper_data_attributes) do+ component_wrapper doprimer_form_with(model: @meeting_outcome,method: @method,@@ -8,10 +8,7 @@grid_layout("op-meeting-outcome-form", tag: :div) do |grid|grid.with_area(:notes,- data: {- "test-selector": "meeting-outcome-input",- "meeting-outcome-form-target": "notesInput"- }+ data: wrapper_data_attributes) dorender(MeetingAgendaItem::Outcome::Notes.new(f))enddiff --git a/modules/meeting/app/components/meeting_agenda_items/outcomes/form_component.rb b/modules/meeting/app/components/meeting_agenda_items/outcomes/form_component.rbindex 7600051dfe3..a3b978491a5 100644--- a/modules/meeting/app/components/meeting_agenda_items/outcomes/form_component.rb+++ b/modules/meeting/app/components/meeting_agenda_items/outcomes/form_component.rb@@ -50,10 +50,12 @@ module MeetingAgendaItems::Outcomesprivatedef wrapper_data_attributes- # {- # controller: "meeting-outcome-form",- # "application-target": "dynamic"- # }+ {+ controller: "ckeditor-focus",+ "test-selector": "meeting-outcome-input",+ "ckeditor-focus-target": "editor",+ "ckeditor-focus-autofocus-value": "true"+ }endendenddiff --git a/modules/meeting/app/forms/meeting_agenda_item/work_package.rb b/modules/meeting/app/forms/meeting_agenda_item/work_package.rbindex eb43d63bdcb..613102e83d4 100644--- a/modules/meeting/app/forms/meeting_agenda_item/work_package.rb+++ b/modules/meeting/app/forms/meeting_agenda_item/work_package.rb@@ -38,14 +38,15 @@ class MeetingAgendaItem::WorkPackage < ApplicationFormdata: {"test-selector": "op-agenda-items-wp-autocomplete"},- focusDirectly: true,+ focusDirectly: @autofocus,disabled: @disabled})end- def initialize(disabled: false)+ def initialize(autofocus:, disabled: false)super()@disabled = disabled+ @autofocus = autofocusendend