diff --git a/src/components/ButtonWithDropdownMenu.js b/src/components/ButtonWithDropdownMenu.js index a16d5044ab58..1396ab601330 100644 --- a/src/components/ButtonWithDropdownMenu.js +++ b/src/components/ButtonWithDropdownMenu.js @@ -54,19 +54,23 @@ function ButtonWithDropdownMenu(props) { const [popoverAnchorPosition, setPopoverAnchorPosition] = useState(null); const {windowWidth, windowHeight} = useWindowDimensions(); const caretButton = useRef(null); + const selectedItem = props.options[selectedItemIndex]; + useEffect(() => { if (!caretButton.current) { return; } + if (!isMenuVisible) { + return; + } caretButton.current.measureInWindow((x, y, w, h) => { setPopoverAnchorPosition({ horizontal: x + w, vertical: y + h, }); }); - }, [windowWidth, windowHeight]); + }, [windowWidth, windowHeight, isMenuVisible]); - const selectedItem = props.options[selectedItemIndex]; return ( {props.options.length > 1 ? ( @@ -87,9 +91,7 @@ function ButtonWithDropdownMenu(props) { success isDisabled={props.isDisabled} style={[styles.pl0]} - onPress={() => { - setIsMenuVisible(true); - }} + onPress={() => setIsMenuVisible(true)} shouldRemoveLeftBorderRadius >