Emoji Picker: Fix losing focus in Safari (#1157)

This commit is contained in:
Alexander Zinchuk 2021-06-13 19:08:01 +03:00
parent 74bc1b4154
commit 16f2a3a18e
3 changed files with 14 additions and 12 deletions

View File

@ -315,6 +315,7 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
const newHtml = renderText(text, ['escape_html', 'emoji_html', 'br_html']) const newHtml = renderText(text, ['escape_html', 'emoji_html', 'br_html'])
.join('') .join('')
.replace(/\u200b+/g, '\u200b'); .replace(/\u200b+/g, '\u200b');
if (selection.rangeCount) { if (selection.rangeCount) {
const selectionRange = selection.getRangeAt(0); const selectionRange = selection.getRangeAt(0);
if (isSelectionInsideInput(selectionRange)) { if (isSelectionInsideInput(selectionRange)) {
@ -327,17 +328,15 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
} }
return; return;
} }
}
setHtml(`${htmlRef.current!}${newHtml}`); setHtml(`${htmlRef.current!}${newHtml}`);
if (!IS_MOBILE_SCREEN) { if (!IS_MOBILE_SCREEN) {
// If selection is outside of input, set cursor at the end of input // If selection is outside of input, set cursor at the end of input
requestAnimationFrame(() => { requestAnimationFrame(() => {
focusEditableElement(messageInput); focusEditableElement(messageInput);
}); });
}
} else {
setHtml(`${htmlRef.current!}${newHtml}`);
} }
}, []); }, []);

View File

@ -11,14 +11,17 @@ type OwnProps = {
}; };
const EmojiButton: FC<OwnProps> = ({ emoji, focus, onClick }) => { const EmojiButton: FC<OwnProps> = ({ emoji, focus, onClick }) => {
const handleClick = useCallback(() => { const handleClick = useCallback((e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
// Preventing safari from losing focus on Composer MessageInput
e.preventDefault();
onClick(emoji.native, emoji.id); onClick(emoji.native, emoji.id);
}, [emoji, onClick]); }, [emoji, onClick]);
return ( return (
<div <div
className={`EmojiButton ${focus ? 'focus' : ''}`} className={`EmojiButton ${focus ? 'focus' : ''}`}
onClick={handleClick} onMouseDown={handleClick}
title={`:${emoji.names[0]}:`} title={`:${emoji.names[0]}:`}
> >
{IS_EMOJI_SUPPORTED {IS_EMOJI_SUPPORTED

View File

@ -79,7 +79,7 @@ const Menu: FC<OwnProps> = ({
} }
}, [isOpen]); }, [isOpen]);
const handleKeyDown = useKeyboardListNavigation(menuRef, isOpen, autoClose ? onClose : undefined); const handleKeyDown = useKeyboardListNavigation(menuRef, isOpen, autoClose ? onClose : undefined, undefined, true);
useVirtualBackdrop( useVirtualBackdrop(
isOpen, isOpen,