From cb9f4f7c05353bc6a891fd5c4a5a6b7bebb5f9ae Mon Sep 17 00:00:00 2001 From: Maurice Williams Date: Sat, 2 Aug 2014 23:17:25 -0400 Subject: [PATCH] Stop event propagation when hitting "enter" in the gh-blur-input component fixes #3516 - new behavior is disabled by default - added new stopEnterKeyDownPropagation property enable new behavior --- core/client/components/gh-blur-input.js | 10 ++++++++++ core/client/templates/post-settings-menu.hbs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/client/components/gh-blur-input.js b/core/client/components/gh-blur-input.js index 8a01b59f70..84d771a6d2 100644 --- a/core/client/components/gh-blur-input.js +++ b/core/client/components/gh-blur-input.js @@ -1,5 +1,6 @@ var BlurInput = Ember.TextField.extend({ selectOnClick: false, + stopEnterKeyDownPropagation: false, click: function (event) { if (this.get('selectOnClick')) { event.currentTarget.select(); @@ -7,6 +8,15 @@ var BlurInput = Ember.TextField.extend({ }, focusOut: function () { this.sendAction('action', this.get('value')); + }, + keyDown: function (event) { + // stop event propagation when pressing "enter" + // most useful in the case when undesired (global) keyboard shortcuts are getting triggered while interacting + // with this particular input element. + if (this.get('stopEnterKeyDownPropagation') && event.keyCode === 13) { + event.stopPropagation(); + return true; + } } }); diff --git a/core/client/templates/post-settings-menu.hbs b/core/client/templates/post-settings-menu.hbs index 04f2a578c6..a0628f1804 100644 --- a/core/client/templates/post-settings-menu.hbs +++ b/core/client/templates/post-settings-menu.hbs @@ -6,7 +6,7 @@ - {{gh-blur-input class="post-setting-slug" id="url" value=slugValue name="post-setting-slug" action="updateSlug" placeholder=slugPlaceholder selectOnClick="true"}} + {{gh-blur-input class="post-setting-slug" id="url" value=slugValue name="post-setting-slug" action="updateSlug" placeholder=slugPlaceholder selectOnClick="true" stopEnterKeyDownPropagation="true"}} @@ -14,7 +14,7 @@ - {{gh-blur-input class="post-setting-date" value=publishedAtValue name="post-setting-date" action="setPublishedAt" placeholder=publishedAtPlaceholder}} + {{gh-blur-input class="post-setting-date" value=publishedAtValue name="post-setting-date" action="setPublishedAt" placeholder=publishedAtPlaceholder stopEnterKeyDownPropagation="true"}}