From 663e4a82cbd4967290af3f1306d9f4a0fdc026ae Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 28 Dec 2023 13:15:50 +0800 Subject: [PATCH 1/4] clear anchor ref when the modal hide --- src/components/EmojiPicker/EmojiPicker.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/EmojiPicker/EmojiPicker.js b/src/components/EmojiPicker/EmojiPicker.js index 532eb61a99a9..96bb18cdae04 100644 --- a/src/components/EmojiPicker/EmojiPicker.js +++ b/src/components/EmojiPicker/EmojiPicker.js @@ -86,7 +86,6 @@ const EmojiPicker = forwardRef((props, ref) => { if (isNavigating) { onModalHide.current = () => {}; } - emojiPopoverAnchorRef.current = null; setIsEmojiPickerVisible(false); }; @@ -162,7 +161,10 @@ const EmojiPicker = forwardRef((props, ref) => { isVisible={isEmojiPickerVisible} onClose={hideEmojiPicker} onModalShow={focusEmojiSearchInput} - onModalHide={onModalHide.current} + onModalHide={() => { + onModalHide.current(); + emojiPopoverAnchorRef.current = null; + }} hideModalContentWhileAnimating shouldSetModalVisibility={false} animationInTiming={1} From c5847a4530fa139e939c64aae09d537f7649bd61 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 30 Dec 2023 14:34:08 +0800 Subject: [PATCH 2/4] clear anchor ref only when we hide the picker --- src/components/EmojiPicker/EmojiPicker.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/EmojiPicker/EmojiPicker.js b/src/components/EmojiPicker/EmojiPicker.js index 96bb18cdae04..468bc9f914e5 100644 --- a/src/components/EmojiPicker/EmojiPicker.js +++ b/src/components/EmojiPicker/EmojiPicker.js @@ -86,6 +86,11 @@ const EmojiPicker = forwardRef((props, ref) => { if (isNavigating) { onModalHide.current = () => {}; } + const currOnModalHide = onModalHide.current; + onModalHide.current = () => { + currOnModalHide(); + emojiPopoverAnchorRef.current = null; + } setIsEmojiPickerVisible(false); }; @@ -161,10 +166,7 @@ const EmojiPicker = forwardRef((props, ref) => { isVisible={isEmojiPickerVisible} onClose={hideEmojiPicker} onModalShow={focusEmojiSearchInput} - onModalHide={() => { - onModalHide.current(); - emojiPopoverAnchorRef.current = null; - }} + onModalHide={onModalHide.current} hideModalContentWhileAnimating shouldSetModalVisibility={false} animationInTiming={1} From f3fef89750210ed0d9821a5df148c0e57d1c60a3 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 30 Dec 2023 14:38:41 +0800 Subject: [PATCH 3/4] lint --- src/components/EmojiPicker/EmojiPicker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/EmojiPicker/EmojiPicker.js b/src/components/EmojiPicker/EmojiPicker.js index 468bc9f914e5..71270fe26c2e 100644 --- a/src/components/EmojiPicker/EmojiPicker.js +++ b/src/components/EmojiPicker/EmojiPicker.js @@ -90,7 +90,7 @@ const EmojiPicker = forwardRef((props, ref) => { onModalHide.current = () => { currOnModalHide(); emojiPopoverAnchorRef.current = null; - } + }; setIsEmojiPickerVisible(false); }; From 3c1df5e01d8ce5d0ef492302047d2b0628dfc6ef Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Mon, 15 Jan 2024 22:14:59 +0800 Subject: [PATCH 4/4] safely execute the callback --- src/components/EmojiPicker/EmojiPicker.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/EmojiPicker/EmojiPicker.js b/src/components/EmojiPicker/EmojiPicker.js index 71270fe26c2e..eaf89b7f64ea 100644 --- a/src/components/EmojiPicker/EmojiPicker.js +++ b/src/components/EmojiPicker/EmojiPicker.js @@ -88,7 +88,9 @@ const EmojiPicker = forwardRef((props, ref) => { } const currOnModalHide = onModalHide.current; onModalHide.current = () => { - currOnModalHide(); + if (currOnModalHide) { + currOnModalHide(); + } emojiPopoverAnchorRef.current = null; }; setIsEmojiPickerVisible(false);