Skip to content

Commit

Permalink
Fix: Emoji picker re-opening by clicking the button to close (bigblue…
Browse files Browse the repository at this point in the history
  • Loading branch information
Scroody authored Aug 29, 2024
1 parent 592fe6d commit 8b117ca
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { layoutSelect } from '/imports/ui/components/layout/context';
import { defineMessages, useIntl } from 'react-intl';
import { useIsChatEnabled } from '/imports/ui/services/features';
import { checkText } from 'smile2emoji';
import { findDOMNode } from 'react-dom';

import Styled from './styles';
import deviceInfo from '/imports/utils/deviceInfo';
import usePreviousValue from '/imports/ui/hooks/usePreviousValue';
Expand Down Expand Up @@ -130,6 +132,7 @@ const ChatMessageForm: React.FC<ChatMessageFormProps> = ({
const [message, setMessage] = React.useState('');
const [showEmojiPicker, setShowEmojiPicker] = React.useState(false);
const emojiPickerRef = useRef<HTMLDivElement>(null);
const emojiPickerButtonRef = useRef(null);
const [isTextAreaFocused, setIsTextAreaFocused] = React.useState(false);
const textAreaRef: RefObject<TextareaAutosize> = useRef<TextareaAutosize>(null);
const { isMobile } = deviceInfo;
Expand Down Expand Up @@ -396,7 +399,12 @@ const ChatMessageForm: React.FC<ChatMessageFormProps> = ({

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (emojiPickerRef.current && !emojiPickerRef.current.contains(event.target as Node)) {
// eslint-disable-next-line react/no-find-dom-node
const button = findDOMNode(emojiPickerButtonRef.current);
if (
(emojiPickerRef.current && !emojiPickerRef.current.contains(event.target as Node))
&& (button && !button.contains(event.target as Node))
) {
setShowEmojiPicker(false);
}
};
Expand Down Expand Up @@ -458,6 +466,7 @@ const ChatMessageForm: React.FC<ChatMessageFormProps> = ({
/>
{ENABLE_EMOJI_PICKER ? (
<Styled.EmojiButton
ref={emojiPickerButtonRef}
onClick={() => setShowEmojiPicker(!showEmojiPicker)}
icon="happy"
color="light"
Expand Down

0 comments on commit 8b117ca

Please sign in to comment.