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)} - > +