From 6b6da04a65ea0fbc28ea5bcb3f7be2e8901402dc Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 5 Aug 2019 16:19:55 -0700 Subject: [PATCH] Fix clicks on sticker picker buttons to page left/right --- ts/components/stickers/StickerButton.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ts/components/stickers/StickerButton.tsx b/ts/components/stickers/StickerButton.tsx index 242494b82c..353a93131f 100644 --- a/ts/components/stickers/StickerButton.tsx +++ b/ts/components/stickers/StickerButton.tsx @@ -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); } };