Skip to content
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(tooltip): tooltip stays open on fast movement #4482

Open
wants to merge 6 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-insects-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@heroui/tooltip": patch
---

fix tooltip staying open on fast movement issue (#4301)
19 changes: 12 additions & 7 deletions packages/components/tooltip/src/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const Tooltip = forwardRef<"div", TooltipProps>((props, ref) => {
<div ref={tooltipRef} id={id} style={style}>
<LazyMotion features={domAnimation}>
<m.div
key={id}
animate="enter"
exit="exit"
initial="exit"
Expand All @@ -79,16 +80,20 @@ const Tooltip = forwardRef<"div", TooltipProps>((props, ref) => {
return (
<>
{trigger}
{disableAnimation && isOpen ? (
<OverlayContainer portalContainer={portalContainer}>
<div ref={tooltipRef} id={id} style={style} {...otherTooltipProps}>
<Component {...getTooltipContentProps()}>{content}</Component>
</div>
</OverlayContainer>
{disableAnimation ? (
isOpen && (
<OverlayContainer portalContainer={portalContainer}>
<div ref={tooltipRef} id={id} style={style} {...otherTooltipProps}>
<Component {...getTooltipContentProps()}>{content}</Component>
</div>
</OverlayContainer>
)
) : (
<AnimatePresence>
{isOpen ? (
<OverlayContainer portalContainer={portalContainer}>{animatedContent}</OverlayContainer>
<OverlayContainer key={id} portalContainer={portalContainer}>
{animatedContent}
</OverlayContainer>
) : null}
</AnimatePresence>
)}
Expand Down
37 changes: 37 additions & 0 deletions packages/components/tooltip/stories/tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,35 @@ const ControlledTemplate = (args: TooltipProps) => {
);
};

const ManyTemplate = (args: TooltipProps) => (
<div className="flex flex-col gap-2">
<Tooltip {...args} closeDelay={0} content="Tooltip 1" openDelay={0}>
<Button>Hover me</Button>
</Tooltip>
<Tooltip {...args} closeDelay={0} content="Tooltip 2" openDelay={0}>
<Button>Then hover me</Button>
</Tooltip>
<Tooltip {...args} closeDelay={0} content="Tooltip 3" openDelay={0}>
<Button>Then hover me</Button>
</Tooltip>
<Tooltip {...args} closeDelay={0} content="Tooltip 4" openDelay={0}>
<Button>Then hover me</Button>
</Tooltip>
<Tooltip {...args} closeDelay={0} content="Tooltip 5" openDelay={0}>
<Button>Then hover me</Button>
</Tooltip>
<Tooltip {...args} closeDelay={0} content="Tooltip 6" openDelay={0}>
<Button>Then hover me</Button>
</Tooltip>
<Tooltip {...args} closeDelay={0} content="Tooltip 7" openDelay={0}>
<Button>Then hover me</Button>
</Tooltip>
<Tooltip {...args} closeDelay={0} content="Tooltip 8" openDelay={0}>
<Button>Then hover me</Button>
</Tooltip>
</div>
);

export const Default = {
args: {
...defaultProps,
Expand Down Expand Up @@ -395,3 +424,11 @@ export const Disabled = {
isDisabled: true,
},
};

export const Many = {
render: ManyTemplate,

args: {
...defaultProps,
},
};