Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Refocus issue on address field on delete and cancel #27653

Merged
merged 6 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions src/components/HeaderWithBackButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function HeaderWithBackButton({
},
threeDotsMenuItems = [],
children = null,
onModalHide = () => {},
shouldOverlay = false,
}) {
const [isDownloadButtonActive, temporarilyDisableDownloadButton] = useThrottledButtonState();
Expand Down Expand Up @@ -138,6 +139,7 @@ function HeaderWithBackButton({
menuItems={threeDotsMenuItems}
onIconPress={onThreeDotsButtonPress}
anchorPosition={threeDotsAnchorPosition}
onModalHide={onModalHide}
shouldOverlay={shouldOverlay}
/>
)}
Expand Down
5 changes: 5 additions & 0 deletions src/components/PopoverMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const propTypes = {
}),

withoutOverlay: PropTypes.bool,

/** Function to call on modal hide */
onModalHide: PropTypes.func,
};

const defaultProps = {
Expand All @@ -44,6 +47,7 @@ const defaultProps = {
},
anchorRef: () => {},
withoutOverlay: false,
onModalHide: () => {},
};

function PopoverMenu(props) {
Expand Down Expand Up @@ -78,6 +82,7 @@ function PopoverMenu(props) {
isVisible={props.isVisible}
onModalHide={() => {
setFocusedIndex(-1);
props.onModalHide();
if (selectedItemIndex.current !== null) {
props.menuItems[selectedItemIndex.current].onSelected();
selectedItemIndex.current = null;
Expand Down
12 changes: 10 additions & 2 deletions src/components/ThreeDotsMenu/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState, useRef} from 'react';
import {View} from 'react-native';
import {InteractionManager, View} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import Icon from '../Icon';
Expand Down Expand Up @@ -46,6 +46,9 @@ const propTypes = {
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
}),

/** Function to call on modal hide */
onModalHide: PropTypes.func,

/** Whether the popover menu should overlay the current view */
shouldOverlay: PropTypes.bool,
};
Expand All @@ -60,10 +63,11 @@ const defaultProps = {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
},
onModalHide: () => {},
shouldOverlay: false,
};

function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, menuItems, anchorPosition, anchorAlignment, shouldOverlay}) {
function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, menuItems, anchorPosition, anchorAlignment, onModalHide, shouldOverlay}) {
const [isPopupMenuVisible, setPopupMenuVisible] = useState(false);
const buttonRef = useRef(null);
const {translate} = useLocalize();
Expand All @@ -73,6 +77,9 @@ function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, me
};

const hidePopoverMenu = () => {
InteractionManager.runAfterInteractions(() => {
onModalHide();
});
setPopupMenuVisible(false);
};

Expand Down Expand Up @@ -105,6 +112,7 @@ function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, me
</View>
<PopoverMenu
onClose={hidePopoverMenu}
onPopoverHide={onModalHide}
isVisible={isPopupMenuVisible}
anchorPosition={anchorPosition}
anchorAlignment={anchorAlignment}
Expand Down
13 changes: 12 additions & 1 deletion src/pages/iou/WaypointEditor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useMemo, useRef, useState} from 'react';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import {View} from 'react-native';
import {InteractionManager, View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import {useIsFocused} from '@react-navigation/native';
Expand Down Expand Up @@ -157,6 +157,15 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI
Navigation.goBack(ROUTES.getMoneyRequestDistanceTabRoute(iouType));
};

const focus = () => {
Krishna2323 marked this conversation as resolved.
Show resolved Hide resolved
InteractionManager.runAfterInteractions(() => {
if (!textInput.current) {
return;
}
textInput.current.focus();
});
};

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand All @@ -179,12 +188,14 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI
onSelected: () => setIsDeleteStopModalOpen(true),
},
]}
onModalHide={focus}
/>
<ConfirmModal
title={translate('distance.deleteWaypoint')}
isVisible={isDeleteStopModalOpen}
onConfirm={deleteStopAndHideModal}
onCancel={() => setIsDeleteStopModalOpen(false)}
onModalHide={focus}
prompt={translate('distance.deleteWaypointConfirmation')}
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
Expand Down
Loading