diff --git a/src/components/Popover/index.js b/src/components/Popover/index.js
index a886fbbd0c6b..174570d5ed7f 100644
--- a/src/components/Popover/index.js
+++ b/src/components/Popover/index.js
@@ -1,17 +1,20 @@
-import React from 'react';
+import React, {useRef} from 'react';
import {createPortal} from 'react-dom';
import {propTypes, defaultProps} from './popoverPropTypes';
import CONST from '../../CONST';
import Modal from '../Modal';
import withWindowDimensions from '../withWindowDimensions';
import PopoverWithoutOverlay from '../PopoverWithoutOverlay';
+import {PopoverContext} from '../PopoverProvider';
/*
* This is a convenience wrapper around the Modal component for a responsive Popover.
* On small screen widths, it uses BottomDocked modal type, and a Popover type on wide screen widths.
*/
function Popover(props) {
- const {isVisible, onClose, isSmallScreenWidth, fullscreen, animationInTiming, onLayout, animationOutTiming, disableAnimation, withoutOverlay, anchorPosition} = props;
+ const {isVisible, onClose, isSmallScreenWidth, fullscreen, animationInTiming, onLayout, animationOutTiming, disableAnimation, withoutOverlay, anchorPosition, anchorRef} = props;
+ const withoutOverlayRef = useRef(null);
+ const {close, popover} = React.useContext(PopoverContext);
// Not adding this inside the PopoverProvider
// because this is an issue on smaller screens as well.
@@ -29,11 +32,19 @@ function Popover(props) {
};
}, [onClose, isVisible]);
+ const onCloseWithPopoverContext = () => {
+ if (popover) {
+ close(anchorRef);
+ }
+ onClose();
+ };
+
if (!fullscreen && !isSmallScreenWidth) {
return createPortal(
, document.body);
+ return createPortal(
+ ,
+ document.body,
+ );
}
return (
{},
disableAnimation: true,
+ withoutOverlayRef: () => {},
};
export {propTypes, defaultProps};
diff --git a/src/components/PopoverWithoutOverlay/index.js b/src/components/PopoverWithoutOverlay/index.js
index 778f65349969..7287f36e7f2c 100644
--- a/src/components/PopoverWithoutOverlay/index.js
+++ b/src/components/PopoverWithoutOverlay/index.js
@@ -10,7 +10,6 @@ import getModalStyles from '../../styles/getModalStyles';
import withWindowDimensions from '../withWindowDimensions';
function Popover(props) {
- const ref = React.useRef(null);
const {onOpen, close} = React.useContext(PopoverContext);
const {modalStyle, modalContainerStyle, shouldAddTopSafeAreaMargin, shouldAddBottomSafeAreaMargin, shouldAddTopSafeAreaPadding, shouldAddBottomSafeAreaPadding} = getModalStyles(
'popover',
@@ -28,7 +27,7 @@ function Popover(props) {
if (props.isVisible) {
props.onModalShow();
onOpen({
- ref,
+ ref: props.withoutOverlayRef,
close: props.onClose,
anchorRef: props.anchorRef,
});
@@ -51,7 +50,7 @@ function Popover(props) {
return (
{(insets) => {