From a53667399f169119a48aa6c52b37483a55f8f87c Mon Sep 17 00:00:00 2001
From: Mohamed Raafat <44686958+mohamedar97@users.noreply.github.com>
Date: Thu, 17 Oct 2019 16:50:13 +0200
Subject: [PATCH] [NEW] close emoji box using Keyboard Escape key (#13956)
---
app/emoji/client/emojiPicker.html | 2 +-
app/emoji/client/emojiPicker.js | 9 +++++++++
app/emoji/client/lib/EmojiPicker.js | 1 +
app/ui-message/client/messageBox/messageBox.js | 4 ++--
4 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/app/emoji/client/emojiPicker.html b/app/emoji/client/emojiPicker.html
index 7b1bec27f027..0e3a5c7546e1 100644
--- a/app/emoji/client/emojiPicker.html
+++ b/app/emoji/client/emojiPicker.html
@@ -7,7 +7,7 @@
{{> icon block="rc-input__icon-svg" icon="magnifier" }}
-
+
diff --git a/app/emoji/client/emojiPicker.js b/app/emoji/client/emojiPicker.js
index 9bc0b89ff7b0..9040f92ffd5f 100644
--- a/app/emoji/client/emojiPicker.js
+++ b/app/emoji/client/emojiPicker.js
@@ -7,6 +7,8 @@ import { t } from '../../utils/client';
import { EmojiPicker } from './lib/EmojiPicker';
import { emoji } from '../lib/rocketchat';
+const ESCAPE = 27;
+
const emojiListByCategory = new ReactiveDict('emojiList');
const getEmojiElement = (emoji, image) => image && `${ image }`;
@@ -226,6 +228,13 @@ Template.emojiPicker.events({
EmojiPicker.pickEmoji(_emoji + tone);
},
'keyup .js-emojipicker-search, change .js-emojipicker-search'(event, instance) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ if (event.keyCode === ESCAPE) {
+ return EmojiPicker.close();
+ }
+
const value = event.target.value.trim();
const cst = instance.currentSearchTerm;
if (value === cst.get()) {
diff --git a/app/emoji/client/lib/EmojiPicker.js b/app/emoji/client/lib/EmojiPicker.js
index c46226adc6d0..98e7038d800f 100644
--- a/app/emoji/client/lib/EmojiPicker.js
+++ b/app/emoji/client/lib/EmojiPicker.js
@@ -113,6 +113,7 @@ export const EmojiPicker = {
close() {
$('.emoji-picker').removeClass('show');
this.opened = false;
+ this.source.focus();
},
pickEmoji(emoji) {
this.pickCallback(emoji);
diff --git a/app/ui-message/client/messageBox/messageBox.js b/app/ui-message/client/messageBox/messageBox.js
index f4fc1289927b..1e1705b7004b 100644
--- a/app/ui-message/client/messageBox/messageBox.js
+++ b/app/ui-message/client/messageBox/messageBox.js
@@ -40,7 +40,6 @@ import './messageBoxReadOnly';
Template.messageBox.onCreated(function() {
this.state = new ReactiveDict();
- EmojiPicker.init();
this.popupConfig = new ReactiveVar(null);
this.replyMessageData = new ReactiveVar();
this.isMicrophoneDenied = new ReactiveVar(true);
@@ -111,6 +110,7 @@ Template.messageBox.onCreated(function() {
Template.messageBox.onRendered(function() {
const $input = $(this.find('.js-input-message'));
+ this.source = $input[0];
$input.on('dataChange', () => {
const messages = $input.data('reply') || [];
this.replyMessageData.set(messages);
@@ -327,7 +327,7 @@ Template.messageBox.events({
return;
}
- EmojiPicker.open(event.currentTarget, (emoji) => {
+ EmojiPicker.open(instance.source, (emoji) => {
const emojiValue = `:${ emoji }: `;
const { input } = instance;