Skip to content

Commit

Permalink
[NEW] close emoji box using Keyboard Escape key (#13956)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedar97 authored and ggazzo committed Oct 17, 2019
1 parent f5d963a commit a536673
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/emoji/client/emojiPicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="rc-input__icon">
{{> icon block="rc-input__icon-svg" icon="magnifier" }}
</div>
<input name="name" type="text" class="rc-input__element js-emojipicker-search" placeholder="{{_ "Search"}}" autocomplete="off">
<input name="name" type="text" class="rc-input__element js-emojipicker-search" placeholder="{{_ "Search"}}" autofocus autocomplete="off">
</div>
</label>
</div>
Expand Down
9 changes: 9 additions & 0 deletions app/emoji/client/emojiPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 && `<li class="emoji-${ emoji } emoji-picker-item" data-emoji="${ emoji }" title="${ emoji }">${ image }</li>`;
Expand Down Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions app/emoji/client/lib/EmojiPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const EmojiPicker = {
close() {
$('.emoji-picker').removeClass('show');
this.opened = false;
this.source.focus();
},
pickEmoji(emoji) {
this.pickCallback(emoji);
Expand Down
4 changes: 2 additions & 2 deletions app/ui-message/client/messageBox/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -327,7 +327,7 @@ Template.messageBox.events({
return;
}

EmojiPicker.open(event.currentTarget, (emoji) => {
EmojiPicker.open(instance.source, (emoji) => {
const emojiValue = `:${ emoji }: `;

const { input } = instance;
Expand Down

0 comments on commit a536673

Please sign in to comment.