]> Untitled Git - lemmy-ui.git/commitdiff
fix: Fix some emoji escape logic
authorJay Sitter <jay@jaysitter.com>
Sat, 24 Jun 2023 20:27:55 +0000 (16:27 -0400)
committerJay Sitter <jay@jaysitter.com>
Sat, 24 Jun 2023 20:29:41 +0000 (16:29 -0400)
src/shared/components/common/emoji-picker.tsx

index d8ddf915e5804c4cb3187d5a53f91446649aca40..1385ce8f919cd61a5b4e75f91239087528a24a2b 100644 (file)
@@ -12,6 +12,10 @@ interface EmojiPickerState {
   showPicker: boolean;
 }
 
+function closeEmojiMartOnEsc(i, event): void {
+  event.key === "Escape" && i.setState({ showPicker: false });
+}
+
 export class EmojiPicker extends Component<EmojiPickerProps, EmojiPickerState> {
   private emptyState: EmojiPickerState = {
     showPicker: false,
@@ -24,10 +28,6 @@ export class EmojiPicker extends Component<EmojiPickerProps, EmojiPickerState> {
     this.handleEmojiClick = this.handleEmojiClick.bind(this);
   }
 
-  closeEmojiMartOnEsc(i, event) {
-    event.key === "Escape" && i.setState({ showPicker: false });
-  }
-
   render() {
     return (
       <span className="emoji-picker">
@@ -44,7 +44,7 @@ export class EmojiPicker extends Component<EmojiPickerProps, EmojiPickerState> {
         {this.state.showPicker && (
           <>
             <div className="position-relative" role="dialog">
-              <div className="emoji-picker-container z-3">
+              <div className="emoji-picker-container">
                 <EmojiMart
                   onEmojiClick={this.handleEmojiClick}
                   pickerOptions={{}}
@@ -61,13 +61,17 @@ export class EmojiPicker extends Component<EmojiPickerProps, EmojiPickerState> {
     );
   }
 
+  componentWillUnmount() {
+    document.removeEventListener("keyup", e => closeEmojiMartOnEsc(this, e));
+  }
+
   togglePicker(i: EmojiPicker, e: any) {
     e.preventDefault();
     i.setState({ showPicker: !i.state.showPicker });
 
     i.state.showPicker
-      ? document.addEventListener("keyup", e => i.closeEmojiMartOnEsc(i, e))
-      : document.removeEventListener("keyup", e => i.closeEmojiMartOnEsc(i, e));
+      ? document.addEventListener("keyup", e => closeEmojiMartOnEsc(i, e))
+      : document.removeEventListener("keyup", e => closeEmojiMartOnEsc(i, e));
   }
 
   handleEmojiClick(e: any) {