From bc0a37b642c38de605b72509e8950540a3583d0e Mon Sep 17 00:00:00 2001 From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com> Date: Wed, 15 Jun 2022 12:36:04 -0500 Subject: [PATCH] DEV: @bind create-account actions (#17100) DEV: @bind create-account actions Context: https://github.com/discourse/discourse/pull/16983#discussion_r894721403 --- .../app/components/create-account.js | 3 +++ .../create-account-user-fields-test.js | 21 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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" + ); + }); });