diff --git a/src/components/Modal/BaseModal.tsx b/src/components/Modal/BaseModal.tsx index 54a178db1cdd..95a7f3adc279 100644 --- a/src/components/Modal/BaseModal.tsx +++ b/src/components/Modal/BaseModal.tsx @@ -56,6 +56,7 @@ function BaseModal( */ const hideModal = useCallback( (callHideCallback = true) => { + Modal.willAlertModalBecomeVisible(false); if (shouldSetModalVisibility) { Modal.setModalVisibility(false); } @@ -77,8 +78,6 @@ function BaseModal( Modal.willAlertModalBecomeVisible(true); // To handle closing any modal already visible when this modal is mounted, i.e. PopoverReportActionContextMenu removeOnCloseListener = Modal.setCloseModal(onClose); - } else if (wasVisible && !isVisible) { - Modal.willAlertModalBecomeVisible(false); } return () => { @@ -96,7 +95,6 @@ function BaseModal( return; } hideModal(true); - Modal.willAlertModalBecomeVisible(false); }, // eslint-disable-next-line react-hooks/exhaustive-deps [], diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js index 6e69f77d0649..663db82a6067 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js @@ -506,7 +506,7 @@ function ComposerWithSuggestions({ InputFocus.inputFocusChange(false); return; } - focus(); + focus(true); }, [focus, prevIsFocused, editFocused, prevIsModalVisible, isFocused, modal.isVisible, isNextModalWillOpenRef]); useEffect(() => { // Scrolls the composer to the bottom and sets the selection to the end, so that longer drafts are easier to edit diff --git a/src/pages/home/report/ReportAttachments.js b/src/pages/home/report/ReportAttachments.js index 173a4b5637be..c580da7887a2 100644 --- a/src/pages/home/report/ReportAttachments.js +++ b/src/pages/home/report/ReportAttachments.js @@ -2,6 +2,7 @@ import PropTypes from 'prop-types'; import React, {useCallback} from 'react'; import _ from 'underscore'; import AttachmentModal from '@components/AttachmentModal'; +import ComposerFocusManager from '@libs/ComposerFocusManager'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import ROUTES from '@src/ROUTES'; @@ -38,7 +39,11 @@ function ReportAttachments(props) { defaultOpen report={report} source={source} - onModalHide={() => Navigation.dismissModal()} + onModalHide={() => { + Navigation.dismissModal(); + // This enables Composer refocus when the attachments modal is closed by the browser navigation + ComposerFocusManager.setReadyToFocus(); + }} onCarouselAttachmentChange={onCarouselAttachmentChange} /> );