-
Notifications
You must be signed in to change notification settings - Fork 3k
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: close popover when history is changed #27452
Changes from 3 commits
9fc3688
197613a
6c5cd02
766041a
62a35bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,23 +11,40 @@ 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB - I'm pretty sure we like to have a blank line above any comments. Not sure why the automations didn't catch that though, so maybe I'm wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prettier did not fix this. Not sure if we have the rule set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah looks like it might not offer that as an option, so maybe we don't have anything automated for that one. Do you mind terribly adding the empty line? I'm checking to make sure I'm not inventing that rule, but I'm pretty sure it's real, haha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
// 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( | ||
<Modal | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
type={CONST.MODAL.MODAL_TYPE.POPOVER} | ||
popoverAnchorPosition={props.anchorPosition} | ||
animationInTiming={props.disableAnimation ? 1 : props.animationInTiming} | ||
animationOutTiming={props.disableAnimation ? 1 : props.animationOutTiming} | ||
popoverAnchorPosition={anchorPosition} | ||
animationInTiming={disableAnimation ? 1 : animationInTiming} | ||
animationOutTiming={disableAnimation ? 1 : animationOutTiming} | ||
shouldCloseOnOutsideClick | ||
onLayout={props.onLayout} | ||
onLayout={onLayout} | ||
/>, | ||
document.body, | ||
); | ||
} | ||
|
||
if (props.withoutOverlay && !props.isSmallScreenWidth) { | ||
if (withoutOverlay && !isSmallScreenWidth) { | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
return createPortal(<PopoverWithoutOverlay {...props} />, document.body); | ||
} | ||
|
@@ -36,12 +53,12 @@ function Popover(props) { | |
<Modal | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
type={props.isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.POPOVER} | ||
popoverAnchorPosition={props.isSmallScreenWidth ? undefined : props.anchorPosition} | ||
fullscreen={props.isSmallScreenWidth ? true : props.fullscreen} | ||
animationInTiming={props.disableAnimation && !props.isSmallScreenWidth ? 1 : props.animationInTiming} | ||
animationOutTiming={props.disableAnimation && !props.isSmallScreenWidth ? 1 : props.animationOutTiming} | ||
onLayout={props.onLayout} | ||
type={isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.POPOVER} | ||
popoverAnchorPosition={isSmallScreenWidth ? undefined : anchorPosition} | ||
fullscreen={isSmallScreenWidth ? true : fullscreen} | ||
animationInTiming={disableAnimation && !isSmallScreenWidth ? 1 : animationInTiming} | ||
animationOutTiming={disableAnimation && !isSmallScreenWidth ? 1 : animationOutTiming} | ||
onLayout={onLayout} | ||
/> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm I understand why you did this, since we need
onClose
andisVisible
as dependencies, we might as well split out all of them?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, splitting everything won't work because we're passing on the
props
object as it is, to theModal
component.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep! that makes sense.