From 4a22e80b5223e752408c63a5c907844698583165 Mon Sep 17 00:00:00 2001 From: "s.sisti@elogic.it" Date: Tue, 3 Nov 2026 10:52:24 +0100 Subject: [PATCH 1/3] UX: Scroll to the top when the wizard step changes When moving to the next step of a long wizard the page stayed scrolled down, or jumped to the first focused field, so the new step's title and description were not visible. Scroll to the top on step change and cancel focus-driven scrolls while the step renders. Co-Authored-By: Claude Opus 5.5 --- .../components/custom-wizard-step.gjs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/assets/javascripts/discourse/components/custom-wizard-step.gjs b/assets/javascripts/discourse/components/custom-wizard-step.gjs index afbc81bd6..1ce793b8f 100644 --- a/assets/javascripts/discourse/components/custom-wizard-step.gjs +++ b/assets/javascripts/discourse/components/custom-wizard-step.gjs @@ -45,6 +45,7 @@ export default class CustomWizardStep extends Component { if (this._stepId !== this.step.id) { this.set("saving", false); this.autoFocus(); + this.scrollToTop(); } } @@ -166,6 +167,33 @@ export default class CustomWizardStep extends Component { }); } + // Start a new step at the top of the page. Focusing the first field (e.g. + // the composer textarea) and async layout changes (cooked title and + // description) scroll the page back down after the route transition, so + // focus-driven scrolls are cancelled for a short window and the scroll is + // repeated a few times while the step renders. + scrollToTop() { + const doScroll = () => { + window.scrollTo({ top: 0, left: 0, behavior: "auto" }); + const main = document.querySelector("#main-outlet, .wizard-column"); + if (main) { + main.scrollTop = 0; + } + }; + const onFocusIn = () => window.requestAnimationFrame(doScroll); + + window.addEventListener("scroll", doScroll, { passive: true }); + document.addEventListener("focusin", onFocusIn, true); + + schedule("afterRender", doScroll); + [0, 50, 150, 350, 700].forEach((delay) => discourseLater(doScroll, delay)); + + discourseLater(() => { + window.removeEventListener("scroll", doScroll); + document.removeEventListener("focusin", onFocusIn, true); + }, 800); + } + animateInvalidFields() { schedule("afterRender", () => { const invalid = document.querySelector(".invalid .wizard-focusable"); From fc7e83fd628b484f6de9fde2dbbff01b6ee1f06c Mon Sep 17 00:00:00 2001 From: "s.sisti@elogic.it" Date: Tue, 3 Nov 2026 11:07:06 +0100 Subject: [PATCH 2/3] Bump version Co-Authored-By: Claude Opus 5.5 --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index b113e3548..4c00af195 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.18.6 +# version: 2.18.7 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Marcos Gutierrez # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 624019c027a2465d7561270d0b8625cf0aa384f7 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 5 Nov 2026 16:46:56 +0700 Subject: [PATCH 3/3] FIX: Don't scroll to the wizard composer when a step loads Core's composer focuses the editor on setup, after the route has scrolled to the top, so steps with a composer field opened scrolled down to it. Focus the wizard composer without scrolling instead of holding the page at the top for a fixed time. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DSz8MWGMF9Utk4gyCsBEcw --- .../custom-wizard-composer-editor.gjs | 9 +++++ .../components/custom-wizard-step.gjs | 28 ------------- spec/system/wizard_step_spec.rb | 40 +++++++++++++++++++ 3 files changed, 49 insertions(+), 28 deletions(-) create mode 100644 spec/system/wizard_step_spec.rb diff --git a/assets/javascripts/discourse/components/custom-wizard-composer-editor.gjs b/assets/javascripts/discourse/components/custom-wizard-composer-editor.gjs index f46efad54..03bf9b3be 100644 --- a/assets/javascripts/discourse/components/custom-wizard-composer-editor.gjs +++ b/assets/javascripts/discourse/components/custom-wizard-composer-editor.gjs @@ -49,6 +49,15 @@ export default class CustomWizardComposerEditor extends ComposerEditor { @bind setupEditor(textManipulation) { textManipulation.placeholder.composer = this.composer; + + // Core focuses the editor on setup, which would scroll the page past the + // step's title and description. + const textarea = textManipulation.textarea; + if (textarea) { + const focus = textarea.focus.bind(textarea); + textarea.focus = (options) => focus({ ...options, preventScroll: true }); + } + super.setupEditor(textManipulation); } diff --git a/assets/javascripts/discourse/components/custom-wizard-step.gjs b/assets/javascripts/discourse/components/custom-wizard-step.gjs index 1ce793b8f..afbc81bd6 100644 --- a/assets/javascripts/discourse/components/custom-wizard-step.gjs +++ b/assets/javascripts/discourse/components/custom-wizard-step.gjs @@ -45,7 +45,6 @@ export default class CustomWizardStep extends Component { if (this._stepId !== this.step.id) { this.set("saving", false); this.autoFocus(); - this.scrollToTop(); } } @@ -167,33 +166,6 @@ export default class CustomWizardStep extends Component { }); } - // Start a new step at the top of the page. Focusing the first field (e.g. - // the composer textarea) and async layout changes (cooked title and - // description) scroll the page back down after the route transition, so - // focus-driven scrolls are cancelled for a short window and the scroll is - // repeated a few times while the step renders. - scrollToTop() { - const doScroll = () => { - window.scrollTo({ top: 0, left: 0, behavior: "auto" }); - const main = document.querySelector("#main-outlet, .wizard-column"); - if (main) { - main.scrollTop = 0; - } - }; - const onFocusIn = () => window.requestAnimationFrame(doScroll); - - window.addEventListener("scroll", doScroll, { passive: true }); - document.addEventListener("focusin", onFocusIn, true); - - schedule("afterRender", doScroll); - [0, 50, 150, 350, 700].forEach((delay) => discourseLater(doScroll, delay)); - - discourseLater(() => { - window.removeEventListener("scroll", doScroll); - document.removeEventListener("focusin", onFocusIn, true); - }, 800); - } - animateInvalidFields() { schedule("afterRender", () => { const invalid = document.querySelector(".invalid .wizard-focusable"); diff --git a/spec/system/wizard_step_spec.rb b/spec/system/wizard_step_spec.rb new file mode 100644 index 000000000..77f38a49b --- /dev/null +++ b/spec/system/wizard_step_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +describe "Wizard steps" do + fab!(:user) + + let(:tall_description) { (1..40).map { |i| "Paragraph #{i}" }.join("\n\n") } + + before do + enable_subscription("standard") + CustomWizard::Template.save( + { + id: "tall_wizard", + name: "Tall wizard", + steps: [ + { + id: "step_1", + raw_description: tall_description, + fields: [{ id: "step_1_field_1", type: "text", label: "First" }], + }, + { + id: "step_2", + raw_description: tall_description, + fields: [{ id: "step_2_field_1", type: "composer", label: "Second" }], + }, + ], + }.as_json, + skip_jobs: true, + ) + sign_in(user) + end + + it "shows the next step from the top when its composer is focused" do + visit("/w/tall-wizard") + page.execute_script("window.scrollTo(0, document.body.scrollHeight)") + find(".wizard-btn.next").click + + expect(page).to have_css(".wizard-step.step_2 .d-editor-input:focus") + expect(page.evaluate_script("window.scrollY")).to eq(0) + end +end