A platform for community discussion. Free, open, simple.
FIX: Allow Enter key to work inside select-kit within modals (#36596)
Régis Hanolf363ae5a15ab
diff --git a/frontend/discourse/app/components/d-modal.gjs b/frontend/discourse/app/components/d-modal.gjsindex c049d8e2731..399883350e9 100644--- a/frontend/discourse/app/components/d-modal.gjs+++ b/frontend/discourse/app/components/d-modal.gjs@@ -100,11 +100,12 @@ export default class DModal extends Component {return false;}- // skip when in a form or a textarea element+ // skip when in a form, textarea, or select-kit elementif (event.target.closest("form") ||document.activeElement?.closest("form") ||- document.activeElement?.nodeName === "TEXTAREA"+ document.activeElement?.nodeName === "TEXTAREA" ||+ document.activeElement?.closest(".select-kit")) {return false;}diff --git a/frontend/discourse/tests/integration/components/d-modal-test.gjs b/frontend/discourse/tests/integration/components/d-modal-test.gjsindex 0f5edddb2ee..2312974d6c4 100644--- a/frontend/discourse/tests/integration/components/d-modal-test.gjs+++ b/frontend/discourse/tests/integration/components/d-modal-test.gjs@@ -222,4 +222,37 @@ module("Integration | Component | d-modal", function (hooks) {assert.true(actionCalled, "pressing enter triggers the default button");});++ test("enter inside select-kit does not trigger default action", async function (assert) {+ let actionCalled = false;+ const someAction = () => {+ actionCalled = true;+ };++ await render(+ <template>+ <DModal @inline={{true}}>+ <:body>+ <div class="select-kit">+ <input class="filter-input" type="text" />+ </div>+ </:body>+ <:footer>+ <DButton+ @action={{someAction}}+ @translatedLabel="Perform action"+ class="btn-primary"+ />+ </:footer>+ </DModal>+ </template>+ );++ await triggerKeyEvent(".filter-input", "keydown", "Enter");++ assert.false(+ actionCalled,+ "pressing enter inside select-kit does not trigger the default button"+ );+ });});diff --git a/plugins/discourse-assign/spec/system/assign_topic_spec.rb b/plugins/discourse-assign/spec/system/assign_topic_spec.rbindex 0ecac549f5a..f55ea484010 100644--- a/plugins/discourse-assign/spec/system/assign_topic_spec.rb+++ b/plugins/discourse-assign/spec/system/assign_topic_spec.rb@@ -51,6 +51,19 @@ describe "Assign | Assigning topics", type: :system doexpect(find("#topic .assigned-to")).to have_content(admin2.username)end+ it "can assign using keyboard navigation" do+ visit "/t/#{topic.id}"++ topic_page.click_assign_topic+ assign_modal.select_assignee_with_keyboard(admin2)+ assign_modal.confirm++ expect(assign_modal).to be_closed++ expect(topic_page).to have_assigned(user: admin2, at_post: 2)+ expect(find("#topic .assigned-to")).to have_content(admin2.username)+ end+context "when prioritize_full_name_in_ux setting is enabled" dobefore { SiteSetting.prioritize_full_name_in_ux = true }diff --git a/plugins/discourse-assign/spec/system/page_objects/modals/assign.rb b/plugins/discourse-assign/spec/system/page_objects/modals/assign.rbindex 91e4fea2b78..dae943b9fd1 100644--- a/plugins/discourse-assign/spec/system/page_objects/modals/assign.rb+++ b/plugins/discourse-assign/spec/system/page_objects/modals/assign.rb@@ -9,6 +9,15 @@ module PageObjectsfind("li[data-value='#{assignee}']").clickend+ def select_assignee_with_keyboard(assignee)+ assignee = assignee.is_a?(Group) ? assignee.name : assignee.username+ input = find(".control-group input")+ input.fill_in(with: assignee)+ find("li[data-value='#{assignee}']")+ input.send_keys(:down)+ input.send_keys(:enter)+ end+def status=(status)find("#assign-status").clickfind("[data-value='#{status}']").click