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
[#61923] Generalise scrollIntoView controller
Mir Bhatia7e10246c3f9e
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..6ee6a4b1fa8 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@@ -51,7 +51,6 @@ export default class extends Controller {focusInput():void {const titleInput = this.element.querySelector('input[name="meeting_agenda_item[title]"]');- this.element.scrollIntoView({ block: 'center' });if (titleInput) {(titleInput as HTMLInputElement).focus();this.setCursorAtEnd(titleInput as HTMLInputElement);diff --git a/frontend/src/stimulus/controllers/dynamic/meeting-section-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/meeting-section-form.controller.tsindex 74280c3d330..93ac0692183 100644--- a/frontend/src/stimulus/controllers/dynamic/meeting-section-form.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/meeting-section-form.controller.ts@@ -45,7 +45,6 @@ export default class extends Controller {focusInput():void {const titleInput = this.element.querySelector('input[name="meeting_section[title]"]');- this.element.scrollIntoView({ block: 'center' });(titleInput as HTMLInputElement).focus();this.setCursorAtEnd(titleInput as HTMLInputElement);}diff --git a/frontend/src/stimulus/controllers/dynamic/meeting-outcome-form.controller.ts b/frontend/src/stimulus/controllers/scroll-into-view.controller.tssimilarity index 78%rename from frontend/src/stimulus/controllers/dynamic/meeting-outcome-form.controller.tsrename to frontend/src/stimulus/controllers/scroll-into-view.controller.tsindex 79b76e85d46..190f7763349 100644--- a/frontend/src/stimulus/controllers/dynamic/meeting-outcome-form.controller.ts+++ b/frontend/src/stimulus/controllers/scroll-into-view.controller.ts@@ -28,14 +28,14 @@* ++*/-import { Controller } from '@hotwired/stimulus';+import { ApplicationController } from 'stimulus-use';-export default class extends Controller {- connect():void {- this.focusInput();- }+export default class ScrollIntoViewController extends ApplicationController {+ connect() {+ super.connect();- focusInput():void {- this.element.scrollIntoView({ block: 'center' });+ setTimeout(() => {+ this.element.scrollIntoView({ block: 'center' });+ }, 0); // Needed because the elements added out of the current view aren't scrolled to otherwise}}diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.tsindex 23e1d7e13d1..34e7b06eddb 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 ScrollIntoViewController from './controllers/scroll-into-view.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('scroll-into-view', ScrollIntoViewController);diff --git a/modules/meeting/app/components/meeting_agenda_items/form_component.rb b/modules/meeting/app/components/meeting_agenda_items/form_component.rbindex 64e8578a9c8..bc1e46fdada 100644--- a/modules/meeting/app/components/meeting_agenda_items/form_component.rb+++ b/modules/meeting/app/components/meeting_agenda_items/form_component.rb@@ -59,7 +59,7 @@ module MeetingAgendaItemsdef wrapper_data_attributes{- controller: "meeting-agenda-item-form",+ controller: "meeting-agenda-item-form scroll-into-view","application-target": "dynamic","meeting-agenda-item-form-cancel-url-value": @cancel_path}diff --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..86944f5f249 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,10 @@ module MeetingAgendaItems::Outcomesprivatedef wrapper_data_attributes- # {- # controller: "meeting-outcome-form",- # "application-target": "dynamic"- # }+ {+ "test-selector": "meeting-outcome-input",+ controller: "scroll-into-view"+ }endendenddiff --git a/modules/meeting/app/components/meeting_sections/header_component.html.erb b/modules/meeting/app/components/meeting_sections/header_component.html.erbindex fb0f49642a3..bd763b7a6db 100644--- a/modules/meeting/app/components/meeting_sections/header_component.html.erb+++ b/modules/meeting/app/components/meeting_sections/header_component.html.erb@@ -43,7 +43,7 @@method: :put,url: meeting_section_path(@meeting_section.meeting, @meeting_section),data: {- controller: "meeting-section-form",+ controller: "meeting-section-form scroll-into-view","application-target": "dynamic","meeting-section-form-cancel-url-value": cancel_edit_meeting_section_path(@meeting_section.meeting, @meeting_section)}