FIX: prevents events on toolbar when in form (#7567)

approved
#1

FIX: prevents events on toolbar when in form (#7567)

If a button is not of type button, pressing enter inside an <input> inside a <form> without the action attribute will trigger the first available <button> as most browsers default the type of an unspecified button to submit.

This commit also prevents d-editor-modal to be filled when it’s hidden.

diff --git a/app/assets/javascripts/discourse/components/d-button.js.es6 b/app/assets/javascripts/discourse/components/d-button.js.es6
index 30ae320..97e1d3c 100644
--- a/app/assets/javascripts/discourse/components/d-button.js.es6
+++ b/app/assets/javascripts/discourse/components/d-button.js.es6
@@ -13,7 +13,8 @@ export default Ember.Component.extend({
     "disabled",
     "translatedTitle:title",
     "translatedLabel:aria-label",
-    "tabindex"
+    "tabindex",
+    "type"
   ],
 
   btnIcon: Ember.computed.notEmpty("icon"),
diff --git a/app/assets/javascripts/discourse/templates/components/d-editor-modal.hbs b/app/assets/javascripts/discourse/templates/components/d-editor-modal.hbs
index 3f9638f..9c1426e 100644
--- a/app/assets/javascripts/discourse/templates/components/d-editor-modal.hbs
+++ b/app/assets/javascripts/discourse/templates/components/d-editor-modal.hbs
@@ -1,7 +1,8 @@
+{{#unless hidden}}
+  {{yield}}
 
-{{yield}}
-
-<div class='controls'>
-  {{d-button class="btn-primary" label="composer.modal_ok" action=(action "ok")}}
-  {{d-button class="btn-danger" label="composer.modal_cancel" action=(action "cancel")}}
-</div>
+  <div class="controls">
+    {{d-button class="btn-primary" label="composer.modal_ok" action=(action "ok")}}
+    {{d-button class="btn-danger" label="composer.modal_cancel" action=(action "cancel")}}
+  </div>
+{{/unless}}
diff --git a/app/assets/javascripts/discourse/templates/components/d-editor.hbs b/app/assets/javascripts/discourse/templates/components/d-editor.hbs
index 244ac0e..544168f 100644
--- a/app/assets/javascripts/discourse/templates/components/d-editor.hbs
+++ b/app/assets/javascripts/discourse/templates/components/d-editor.hbs
@@ -24,6 +24,7 @@
           {{else}}
             {{d-button
               action=b.action
+              type="button"
               actionParam=b
               translatedTitle=b.title
               label=b.label

GitHub sha: b05d7042

Approved #2