diff --git a/app/assets/javascripts/discourse/app/components/create-account.js b/app/assets/javascripts/discourse/app/components/create-account.js index a56b945bc03..695cbc1c33a 100644 --- a/app/assets/javascripts/discourse/app/components/create-account.js +++ b/app/assets/javascripts/discourse/app/components/create-account.js @@ -1,5 +1,6 @@ import Component from "@ember/component"; import cookie from "discourse/lib/cookie"; +import { bind } from "discourse-common/utils/decorators"; export default Component.extend({ classNames: ["create-account-body"], @@ -21,6 +22,7 @@ export default Component.extend({ } }, + @bind actionOnEnter(event) { if (!this.disabled && event.key === "Enter") { event.preventDefault(); @@ -30,6 +32,7 @@ export default Component.extend({ } }, + @bind selectKitFocus(event) { const target = document.getElementById(event.target.getAttribute("for")); if (target?.classList.contains("select-kit")) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/create-account-user-fields-test.js b/app/assets/javascripts/discourse/tests/acceptance/create-account-user-fields-test.js index bfeb8222e11..9572d3cbde0 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/create-account-user-fields-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/create-account-user-fields-test.js @@ -1,9 +1,10 @@ import { acceptance, + count, exists, query, } from "discourse/tests/helpers/qunit-helpers"; -import { click, fillIn, visit } from "@ember/test-helpers"; +import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers"; import { test } from "qunit"; acceptance("Create Account - User Fields", function (needs) { @@ -65,4 +66,22 @@ acceptance("Create Account - User Fields", function (needs) { await click(".user-field input[type=checkbox]"); await click(".modal-footer .btn-primary"); }); + + test("can submit with enter", async function (assert) { + await visit("/"); + await click("header .sign-up-button"); + + await triggerKeyEvent(".modal-footer .btn-primary", "keydown", 13); + + assert.strictEqual( + count("#modal-alert:visible"), + 1, + "hitting Enter triggers modal action" + ); + assert.strictEqual( + count(".d-modal:visible"), + 1, + "hitting Enter does not dismiss modal due to alert error" + ); + }); });