From ae4c37ed4450b194719859413983d6ec651e9609 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Fri, 6 Oct 2023 12:56:36 +0000 Subject: [PATCH] fix: Fix emoji picker custom emoji bug (#2175) * Make emoji picker insert custom emojis * Close emoji picker after emoji is selected --- src/shared/components/common/emoji-mart.tsx | 19 +++++++++++-------- src/shared/components/common/emoji-picker.tsx | 1 + .../components/common/markdown-textarea.tsx | 17 ++++++++--------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/shared/components/common/emoji-mart.tsx b/src/shared/components/common/emoji-mart.tsx index 0f6977b6..fad871c1 100644 --- a/src/shared/components/common/emoji-mart.tsx +++ b/src/shared/components/common/emoji-mart.tsx @@ -1,4 +1,4 @@ -import { Component } from "inferno"; +import { Component, RefObject, createRef } from "inferno"; import { getEmojiMart } from "../../markdown"; interface EmojiMartProps { @@ -7,21 +7,24 @@ interface EmojiMartProps { } export class EmojiMart extends Component { + div: RefObject; + constructor(props: any, context: any) { super(props, context); + + this.div = createRef(); + this.handleEmojiClick = this.handleEmojiClick.bind(this); } + componentDidMount() { - const div: any = document.getElementById("emoji-picker"); - if (div) { - div.appendChild( - getEmojiMart(this.handleEmojiClick, this.props.pickerOptions), - ); - } + this.div.current?.appendChild( + getEmojiMart(this.handleEmojiClick, this.props.pickerOptions) as any, + ); } render() { - return
; + return
; } handleEmojiClick(e: any) { diff --git a/src/shared/components/common/emoji-picker.tsx b/src/shared/components/common/emoji-picker.tsx index 7eac4cf4..0d131be4 100644 --- a/src/shared/components/common/emoji-picker.tsx +++ b/src/shared/components/common/emoji-picker.tsx @@ -77,5 +77,6 @@ export class EmojiPicker extends Component { handleEmojiClick(e: any) { this.props.onEmojiClick?.(e); + this.setState({ showPicker: false }); } } diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index 41f97938..725bfa7e 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -89,6 +89,7 @@ export class MarkdownTextArea extends Component< super(props, context); this.handleLanguageChange = this.handleLanguageChange.bind(this); + this.handleEmoji = this.handleEmoji.bind(this); if (isBrowser()) { this.tribute = setupTribute(); @@ -163,9 +164,7 @@ export class MarkdownTextArea extends Component< {this.getFormatButton("bold", this.handleInsertBold)} {this.getFormatButton("italic", this.handleInsertItalic)} {this.getFormatButton("link", this.handleInsertLink)} - this.handleEmoji(this, e)} - > +