From d41f80518a73a7411e609c044eed031870ab09f1 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 29 Aug 2020 14:19:43 -0700 Subject: [PATCH] fix bug to resize PosePicker when it changes Previously, toggling between the two PosePicker modes could dramatically disrupt the layout, because Popover didn't know to re-measure itself. In this change, we add a hacky workaround to simulate a window resize event in moments when we know the content is changing. (The realistic ideal solution would still have these manual triggers, but would use an official API in Chakra to notify the Popper instance directly.) --- src/app/WardrobePage/PosePicker.js | 12 +++++++++++- src/app/WardrobePage/support/PosePickerSupport.js | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/app/WardrobePage/PosePicker.js b/src/app/WardrobePage/PosePicker.js index 714e82f..d4f244e 100644 --- a/src/app/WardrobePage/PosePicker.js +++ b/src/app/WardrobePage/PosePicker.js @@ -68,6 +68,16 @@ function PosePicker({ false ); + // Resize the Popover when we toggle support mode, because it probably will + // affect the content size. + React.useLayoutEffect(() => { + // HACK: To trigger a Popover resize, we simulate a window resize event, + // because Popover listens for window resizes to reposition itself. + // I've also filed an issue requesting an official API! + // https://github.com/chakra-ui/chakra-ui/issues/1853 + window.dispatchEvent(new Event("resize")); + }, [isInSupportMode]); + if (loading) { return null; } @@ -141,7 +151,7 @@ function PosePicker({ - + {isInSupportMode ? ( { + // HACK: To trigger a Popover resize, we simulate a window resize event, + // because Popover listens for window resizes to reposition itself. + // I've also filed an issue requesting an official API! + // https://github.com/chakra-ui/chakra-ui/issues/1853 + window.dispatchEvent(new Event("resize")); + }, [loading]); + if (loading) { return (