Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/components/PopoverMenu/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'underscore';
import React from 'react';
import React, {useState} from 'react';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import PopoverWithMeasuredContent from '../PopoverWithMeasuredContent';
Expand Down Expand Up @@ -40,11 +40,12 @@ const defaultProps = {

const PopoverMenu = (props) => {
const {isSmallScreenWidth} = useWindowDimensions();
const [selectedItemIndex, setSelectedItemIndex] = useState(null);

const selectItem = (index) => {
const selectedItem = props.menuItems[index];
props.onItemSelected(selectedItem);
selectedItem.onSelected();
setSelectedItemIndex(index);
};

const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({initialFocusedIndex: -1, maxIndex: props.menuItems.length - 1});
Expand All @@ -66,7 +67,13 @@ const PopoverMenu = (props) => {
anchorAlignment={props.anchorOrigin}
onClose={props.onClose}
isVisible={props.isVisible}
onModalHide={() => setFocusedIndex(-1)}
onModalHide={() => {
setFocusedIndex(-1);
if (selectedItemIndex !== null) {
props.menuItems[selectedItemIndex].onSelected();
setSelectedItemIndex(null);
}
}}
animationIn={props.animationIn}
animationOut={props.animationOut}
animationInTiming={props.animationInTiming}
Expand Down