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/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 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