Skip to content

Commit ff66221

Browse files
committed
feat: add interactive option to Tooltip component
1 parent bde3853 commit ff66221

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

example/src/stories/Tooltip.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export default {
4545
description: 'The placement of the tooltip',
4646
defaultValue: 'top',
4747
},
48+
interactive: {
49+
control: 'boolean',
50+
description:
51+
'Whether to make the tooltip interactive - if set to true, the tooltip contents will receive pointer events',
52+
defaultValue: false,
53+
},
4854
},
4955
} as Meta<typeof Tooltip>
5056

src/components/Tooltip.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
flip,
77
FloatingPortal,
88
offset,
9+
safePolygon,
910
shift,
1011
useFloating,
1112
useHover,
@@ -27,7 +28,6 @@ const TooltipContainer = styled(motion(Card))`
2728
border: ${({ theme }) => theme.styles.border()};
2829
box-shadow: ${({ theme }) => theme.styles.shadow(undefined, 16)};
2930
z-index: 30000;
30-
pointer-events: none;
3131
backdrop-filter: blur(4px);
3232
font-size: initial;
3333
font-weight: initial;
@@ -67,6 +67,7 @@ export type TooltipProps = {
6767
arrow?: boolean
6868
keepOpen?: boolean
6969
place?: TooltipPlacement
70+
interactive?: boolean
7071
} & (
7172
| {
7273
noDefaultStyles: false
@@ -121,6 +122,7 @@ export const Tooltip: React.FC<TooltipProps> = (props) => {
121122
arrow: drawArrow = true,
122123
keepOpen = false,
123124
place,
125+
interactive = false,
124126
...cardProps
125127
} = props
126128
const [isOpen, setIsOpen] = useState(false)
@@ -156,6 +158,10 @@ export const Tooltip: React.FC<TooltipProps> = (props) => {
156158
const { getReferenceProps, getFloatingProps } = useInteractions([
157159
useHover(context, {
158160
delay: 200,
161+
move: true,
162+
handleClose: safePolygon({
163+
buffer: 1,
164+
}),
159165
}),
160166
])
161167

@@ -181,6 +187,7 @@ export const Tooltip: React.FC<TooltipProps> = (props) => {
181187
position: strategy,
182188
top: y || 0,
183189
left: x || 0,
190+
pointerEvents: interactive ? 'auto' : 'none',
184191
},
185192
})}
186193
{...cardProps}

0 commit comments

Comments
 (0)