Fix message input emoji focus close (#4727)
This commit is contained in:
parent
2501584db6
commit
062a1f7dd9
3 changed files with 13 additions and 11 deletions
|
@ -260,6 +260,7 @@ export const CompositionArea = ({
|
||||||
i18n={i18n}
|
i18n={i18n}
|
||||||
doSend={handleForceSend}
|
doSend={handleForceSend}
|
||||||
onPickEmoji={insertEmoji}
|
onPickEmoji={insertEmoji}
|
||||||
|
onClose={focusInput}
|
||||||
recentEmojis={recentEmojis}
|
recentEmojis={recentEmojis}
|
||||||
skinTone={skinTone}
|
skinTone={skinTone}
|
||||||
onSetSkinTone={onSetSkinTone}
|
onSetSkinTone={onSetSkinTone}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { LocalizerType } from '../../types/Util';
|
||||||
|
|
||||||
export type OwnProps = {
|
export type OwnProps = {
|
||||||
readonly i18n: LocalizerType;
|
readonly i18n: LocalizerType;
|
||||||
|
readonly onClose?: () => unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Props = OwnProps &
|
export type Props = OwnProps &
|
||||||
|
@ -23,6 +24,7 @@ export const EmojiButton = React.memo(
|
||||||
({
|
({
|
||||||
i18n,
|
i18n,
|
||||||
doSend,
|
doSend,
|
||||||
|
onClose,
|
||||||
onPickEmoji,
|
onPickEmoji,
|
||||||
skinTone,
|
skinTone,
|
||||||
onSetSkinTone,
|
onSetSkinTone,
|
||||||
|
@ -43,7 +45,10 @@ export const EmojiButton = React.memo(
|
||||||
|
|
||||||
const handleClose = React.useCallback(() => {
|
const handleClose = React.useCallback(() => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}, [setOpen]);
|
if (onClose) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
}, [setOpen, onClose]);
|
||||||
|
|
||||||
// Create popper root and handle outside clicks
|
// Create popper root and handle outside clicks
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
@ -51,9 +56,11 @@ export const EmojiButton = React.memo(
|
||||||
const root = document.createElement('div');
|
const root = document.createElement('div');
|
||||||
setPopperRoot(root);
|
setPopperRoot(root);
|
||||||
document.body.appendChild(root);
|
document.body.appendChild(root);
|
||||||
const handleOutsideClick = ({ target }: MouseEvent) => {
|
const handleOutsideClick = (event: MouseEvent) => {
|
||||||
if (!root.contains(target as Node)) {
|
if (!root.contains(event.target as Node)) {
|
||||||
setOpen(false);
|
handleClose();
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
document.addEventListener('click', handleOutsideClick);
|
document.addEventListener('click', handleOutsideClick);
|
||||||
|
@ -66,7 +73,7 @@ export const EmojiButton = React.memo(
|
||||||
}
|
}
|
||||||
|
|
||||||
return noop;
|
return noop;
|
||||||
}, [open, setOpen, setPopperRoot]);
|
}, [open, setOpen, setPopperRoot, handleClose]);
|
||||||
|
|
||||||
// Install keyboard shortcut to open emoji picker
|
// Install keyboard shortcut to open emoji picker
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import {
|
||||||
} from 'lodash';
|
} from 'lodash';
|
||||||
import { Emoji } from './Emoji';
|
import { Emoji } from './Emoji';
|
||||||
import { dataByCategory, search } from './lib';
|
import { dataByCategory, search } from './lib';
|
||||||
import { useRestoreFocus } from '../../util/hooks';
|
|
||||||
import { LocalizerType } from '../../types/Util';
|
import { LocalizerType } from '../../types/Util';
|
||||||
|
|
||||||
export type EmojiPickDataType = {
|
export type EmojiPickDataType = {
|
||||||
|
@ -75,7 +74,6 @@ export const EmojiPicker = React.memo(
|
||||||
}: Props,
|
}: Props,
|
||||||
ref
|
ref
|
||||||
) => {
|
) => {
|
||||||
const focusRef = React.useRef<HTMLButtonElement>(null);
|
|
||||||
const [firstRecent] = React.useState(recentEmojis);
|
const [firstRecent] = React.useState(recentEmojis);
|
||||||
const [selectedCategory, setSelectedCategory] = React.useState(
|
const [selectedCategory, setSelectedCategory] = React.useState(
|
||||||
categories[0]
|
categories[0]
|
||||||
|
@ -188,9 +186,6 @@ export const EmojiPicker = React.memo(
|
||||||
};
|
};
|
||||||
}, [onClose, searchMode]);
|
}, [onClose, searchMode]);
|
||||||
|
|
||||||
// Focus after initial render, restore focus on teardown
|
|
||||||
useRestoreFocus(focusRef);
|
|
||||||
|
|
||||||
const [, ...renderableCategories] = categories;
|
const [, ...renderableCategories] = categories;
|
||||||
|
|
||||||
const emojiGrid = React.useMemo(() => {
|
const emojiGrid = React.useMemo(() => {
|
||||||
|
@ -307,7 +302,6 @@ export const EmojiPicker = React.memo(
|
||||||
<header className="module-emoji-picker__header">
|
<header className="module-emoji-picker__header">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
ref={focusRef}
|
|
||||||
onClick={handleToggleSearch}
|
onClick={handleToggleSearch}
|
||||||
title={i18n('EmojiPicker--search-placeholder')}
|
title={i18n('EmojiPicker--search-placeholder')}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue