From 2cb0fe8c2102707c7b5fd024103cda409d8d3d2d Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 5 Sep 2023 10:35:10 +0700 Subject: [PATCH] fix: pressing enter doesn't open the selected option page --- src/components/PopoverMenu/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/PopoverMenu/index.js b/src/components/PopoverMenu/index.js index 67b9a0406aef..5fabf73547ea 100644 --- a/src/components/PopoverMenu/index.js +++ b/src/components/PopoverMenu/index.js @@ -1,5 +1,5 @@ import _ from 'underscore'; -import React, {useState} from 'react'; +import React, {useRef} from 'react'; import PropTypes from 'prop-types'; import {View} from 'react-native'; import PopoverWithMeasuredContent from '../PopoverWithMeasuredContent'; @@ -48,13 +48,13 @@ const defaultProps = { function PopoverMenu(props) { const {isSmallScreenWidth} = useWindowDimensions(); - const [selectedItemIndex, setSelectedItemIndex] = useState(null); + const selectedItemIndex = useRef(null); const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({initialFocusedIndex: -1, maxIndex: props.menuItems.length - 1, isActive: props.isVisible}); const selectItem = (index) => { const selectedItem = props.menuItems[index]; props.onItemSelected(selectedItem, index); - setSelectedItemIndex(index); + selectedItemIndex.current = index; }; useKeyboardShortcut( @@ -78,9 +78,9 @@ function PopoverMenu(props) { isVisible={props.isVisible} onModalHide={() => { setFocusedIndex(-1); - if (selectedItemIndex !== null) { - props.menuItems[selectedItemIndex].onSelected(); - setSelectedItemIndex(null); + if (selectedItemIndex.current !== null) { + props.menuItems[selectedItemIndex.current].onSelected(); + selectedItemIndex.current = null; } }} animationIn={props.animationIn}