forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Expensify#30150 from allroundexperts/fix-24296
Add popover anchor tooltip
- Loading branch information
Showing
11 changed files
with
74 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, {useContext, useRef, useMemo} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {propTypes as tooltipPropTypes, defaultProps as tooltipDefaultProps} from './tooltipPropTypes'; | ||
import BaseTooltip from './BaseTooltip'; | ||
import {PopoverContext} from '../PopoverProvider'; | ||
|
||
const propTypes = { | ||
...tooltipPropTypes, | ||
|
||
/** Whether the actual Tooltip should be rendered. If false, it's just going to return the children */ | ||
shouldRender: PropTypes.bool, | ||
}; | ||
|
||
const defaultProps = { | ||
...tooltipDefaultProps, | ||
shouldRender: true, | ||
}; | ||
|
||
function PopoverAnchorTooltip({shouldRender, children, ...props}) { | ||
const {isOpen, popover} = useContext(PopoverContext); | ||
const tooltipRef = useRef(null); | ||
|
||
const isPopoverRelatedToTooltipOpen = useMemo(() => { | ||
// eslint-disable-next-line | ||
const tooltipNode = tooltipRef.current ? tooltipRef.current._childNode : null; | ||
if ( | ||
isOpen && | ||
popover && | ||
popover.anchorRef && | ||
popover.anchorRef.current && | ||
tooltipNode && | ||
(tooltipNode.contains(popover.anchorRef.current) || tooltipNode === popover.anchorRef.current) | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}, [isOpen, popover]); | ||
|
||
if (!shouldRender || isPopoverRelatedToTooltipOpen) { | ||
return children; | ||
} | ||
|
||
return ( | ||
<BaseTooltip | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
tooltipRef={tooltipRef} | ||
> | ||
{children} | ||
</BaseTooltip> | ||
); | ||
} | ||
|
||
PopoverAnchorTooltip.displayName = 'PopoverAnchorTooltip'; | ||
PopoverAnchorTooltip.propTypes = propTypes; | ||
PopoverAnchorTooltip.defaultProps = defaultProps; | ||
|
||
export default PopoverAnchorTooltip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters