Skip to content

A platform for community discussion. Free, open, simple.

FIX: Open poll settings when the mobile composer is unfocused (#43584)

Renato Atiliod882ecf92068
diff --git a/plugins/poll/assets/javascripts/discourse/components/poll-node-view.gjs b/plugins/poll/assets/javascripts/discourse/components/poll-node-view.gjs
index 960498ee936..22438f2c5aa 100644
--- a/plugins/poll/assets/javascripts/discourse/components/poll-node-view.gjs
+++ b/plugins/poll/assets/javascripts/discourse/components/poll-node-view.gjs
@@ -184,6 +184,7 @@ export default class PollNodeView extends Component {
@action={{this.editPoll}}
@icon="pencil"
@label="poll.ui_builder.edit"
+ @preventFocus={{true}}
/>
</div>
</template>
diff --git a/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js b/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js
index 2098989b351..f462f9e657f 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js
+++ b/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js
@@ -1,7 +1,9 @@
import {
click,
fillIn,
+ find,
findAll,
+ focus,
settled,
triggerKeyEvent,
visit,
@@ -115,6 +117,35 @@ acceptance("Poll Builder - polls are enabled", function (needs) {
);
});
+ test("opens poll settings without focusing the unfocused editor first", async function (assert) {
+ await visit("/");
+ await click("#create-topic");
+ await fillIn(".d-editor-input", "[poll]\n* First\n* Second\n[/poll]");
+ await click(".composer-toggle-switch");
+ await waitFor(".ProseMirror");
+ await settled();
+ await focus("#reply-title");
+
+ const editButton = find(".composer-poll-node__edit");
+ const mouseDown = new MouseEvent("mousedown", {
+ bubbles: true,
+ cancelable: true,
+ });
+ editButton.dispatchEvent(mouseDown);
+
+ assert.true(
+ mouseDown.defaultPrevented,
+ "pressing Edit poll prevents a focus change that would shift the composer"
+ );
+ assert.dom("#reply-title").isFocused("focus stays outside the editor");
+
+ await click(editButton);
+
+ assert
+ .dom(".poll-ui-builder .d-modal__title")
+ .hasText("Edit poll", "opens the editing builder on the first click");
+ });
+
test("cancelling poll edits leaves the document unchanged", async function (assert) {
await visit("/");
await click("#create-topic");