diff --git a/src/components/Popover/index.js b/src/components/Popover/index.js index bfd02ba1d3e3..a886fbbd0c6b 100644 --- a/src/components/Popover/index.js +++ b/src/components/Popover/index.js @@ -11,23 +11,41 @@ import PopoverWithoutOverlay from '../PopoverWithoutOverlay'; * On small screen widths, it uses BottomDocked modal type, and a Popover type on wide screen widths. */ function Popover(props) { - if (!props.fullscreen && !props.isSmallScreenWidth) { + const {isVisible, onClose, isSmallScreenWidth, fullscreen, animationInTiming, onLayout, animationOutTiming, disableAnimation, withoutOverlay, anchorPosition} = props; + + // Not adding this inside the PopoverProvider + // because this is an issue on smaller screens as well. + React.useEffect(() => { + const listener = () => { + if (!isVisible) { + return; + } + + onClose(); + }; + window.addEventListener('popstate', listener); + return () => { + window.removeEventListener('popstate', listener); + }; + }, [onClose, isVisible]); + + if (!fullscreen && !isSmallScreenWidth) { return createPortal( , document.body, ); } - if (props.withoutOverlay && !props.isSmallScreenWidth) { + if (withoutOverlay && !isSmallScreenWidth) { // eslint-disable-next-line react/jsx-props-no-spreading return createPortal(, document.body); } @@ -36,12 +54,12 @@ function Popover(props) { ); }