Fix clicks on sticker picker buttons to page left/right

This commit is contained in:
Scott Nonnenberg 2019-08-05 16:19:55 -07:00
parent 2beb421067
commit 6b6da04a65

View file

@ -116,7 +116,18 @@ export const StickerButton = React.memo(
setPopperRoot(root);
document.body.appendChild(root);
const handleOutsideClick = ({ target }: MouseEvent) => {
if (!root.contains(target as Node)) {
const targetElement = target as HTMLElement;
const className = targetElement
? targetElement.className || ''
: '';
// We need to special-case sticker picker header buttons, because they can
// disappear after being clicked, which breaks the .contains() check below.
const isMissingButtonClass =
!className ||
className.indexOf('module-sticker-picker__header__button') < 0;
if (!root.contains(targetElement) && isMissingButtonClass) {
setOpen(false);
}
};