UX: flat-btn should also respond to Enter (#15584)

UX: flat-btn should also respond to Enter (#15584)

diff --git a/app/assets/javascripts/discourse/app/components/flat-button.js b/app/assets/javascripts/discourse/app/components/flat-button.js
index 8f8ac08..3e83a64 100644
--- a/app/assets/javascripts/discourse/app/components/flat-button.js
+++ b/app/assets/javascripts/discourse/app/components/flat-button.js
@@ -14,7 +14,15 @@ export default Component.extend({
     }
   },
 
+  keyDown(event) {
+    if (event.key === "Enter") {
+      this.action?.();
+      return false;
+    }
+  },
+
   click() {
-    return this.attrs.action();
+    this.action?.();
+    return false;
   },
 });
diff --git a/app/assets/javascripts/discourse/tests/integration/components/flat-button-test.js b/app/assets/javascripts/discourse/tests/integration/components/flat-button-test.js
new file mode 100644
index 0000000..8b3e55a
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/integration/components/flat-button-test.js
@@ -0,0 +1,47 @@
+import componentTest, {
+  setupRenderingTest,
+} from "discourse/tests/helpers/component-test";
+import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
+import { click, triggerKeyEvent } from "@ember/test-helpers";
+import hbs from "htmlbars-inline-precompile";
+
+discourseModule("Integration | Component | flat-button", function (hooks) {
+  setupRenderingTest(hooks);
+
+  componentTest("press Enter", {
+    template: hbs`{{flat-button action=action}}`,
+
+    beforeEach() {
+      this.set("foo", null);
+      this.set("action", () => {
+        this.set("foo", "bar");
+      });
+    },
+
+    async test(assert) {
+      await triggerKeyEvent(".btn-flat", "keydown", 32);
+
+      assert.strictEqual(this.foo, null);
+
+      await triggerKeyEvent(".btn-flat", "keydown", 13);
+
+      assert.strictEqual(this.foo, "bar");
+    },
+  });
+  componentTest("click", {
+    template: hbs`{{flat-button action=action}}`,
+
+    beforeEach() {
+      this.set("foo", null);
+      this.set("action", () => {
+        this.set("foo", "bar");
+      });
+    },
+
+    async test(assert) {
+      await click(".btn-flat");
+
+      assert.strictEqual(this.foo, "bar");
+    },
+  });
+});

GitHub sha: c758e2cdd17cc7f8cc44596e72d60e81b5bd8def

This commit appears in #15584 which was approved by ZogStriP. It was merged by jjaffeux.