Skip to content

Commit d646f6b

Browse files
authored
Merge pull request #63 from solved-ac/feature/tooltip-interactions
feat(Tooltip): activateOnHover, activateOnClick
2 parents b2ef7a6 + a13bc24 commit d646f6b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

example/src/stories/Tooltip.stories.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ export default {
5151
'Whether to make the tooltip interactive - if set to true, the tooltip contents will receive pointer events',
5252
defaultValue: false,
5353
},
54+
activateOnHover: {
55+
control: 'boolean',
56+
description: 'Whether to activate the tooltip on mouse hover',
57+
defaultValue: true,
58+
},
59+
activateOnClick: {
60+
control: 'boolean',
61+
description:
62+
'Whether to activate the tooltip on mouse click - repeated clicks will toggle the tooltip',
63+
defaultValue: false,
64+
},
5465
},
5566
} as Meta<typeof Tooltip>
5667

src/components/Tooltip.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
offset,
99
safePolygon,
1010
shift,
11+
useClick,
1112
useFloating,
1213
useHover,
1314
useInteractions,
@@ -68,6 +69,8 @@ export type TooltipProps = {
6869
keepOpen?: boolean
6970
place?: TooltipPlacement
7071
interactive?: boolean
72+
activateOnHover?: boolean
73+
activateOnClick?: boolean
7174
} & (
7275
| {
7376
noDefaultStyles: false
@@ -123,6 +126,8 @@ export const Tooltip: React.FC<TooltipProps> = (props) => {
123126
keepOpen = false,
124127
place,
125128
interactive = false,
129+
activateOnHover = true,
130+
activateOnClick = false,
126131
...cardProps
127132
} = props
128133
const [isOpen, setIsOpen] = useState(false)
@@ -157,12 +162,16 @@ export const Tooltip: React.FC<TooltipProps> = (props) => {
157162

158163
const { getReferenceProps, getFloatingProps } = useInteractions([
159164
useHover(context, {
165+
enabled: activateOnHover,
160166
delay: 200,
161167
move: true,
162168
handleClose: safePolygon({
163169
buffer: 1,
164170
}),
165171
}),
172+
useClick(context, {
173+
enabled: activateOnClick,
174+
}),
166175
])
167176

168177
const RenderComponent = noBackground ? motion.div : TooltipContainer

0 commit comments

Comments
 (0)