Skip to content

Commit f712cfa

Browse files
authored
fix(tooltip): Show tooltip on first tap for touch devices (pmndrs#1185)
1 parent bea61cd commit f712cfa

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/tooltip/src/components/TooltipWrapper.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const tooltipStyle = {
2121
left: 0,
2222
}
2323

24+
const translate = (x, y) => `translate(${x}px, ${y}px)`
25+
2426
const TooltipWrapper = ({ position, anchor, children }) => {
2527
const theme = useTheme()
2628
const { animate, config: springConfig } = useMotionConfig()
@@ -29,12 +31,12 @@ const TooltipWrapper = ({ position, anchor, children }) => {
2931

3032
let to = undefined
3133
let immediate = false
32-
3334
const hasDimension = bounds.width > 0 && bounds.height > 0
34-
if (hasDimension) {
35-
let x = Math.round(position[0])
36-
let y = Math.round(position[1])
3735

36+
let x = Math.round(position[0])
37+
let y = Math.round(position[1])
38+
39+
if (hasDimension) {
3840
if (anchor === 'top') {
3941
x -= bounds.width / 2
4042
y -= bounds.height + TOOLTIP_OFFSET
@@ -53,7 +55,7 @@ const TooltipWrapper = ({ position, anchor, children }) => {
5355
}
5456

5557
to = {
56-
transform: `translate(${x}px, ${y}px)`,
58+
transform: translate(x, y),
5759
}
5860
if (!previousPosition.current) {
5961
immediate = true
@@ -71,8 +73,7 @@ const TooltipWrapper = ({ position, anchor, children }) => {
7173
const style = {
7274
...tooltipStyle,
7375
...theme.tooltip,
74-
transform: animatedProps.transform,
75-
opacity: animatedProps.transform ? 1 : 0,
76+
transform: animatedProps.transform ?? translate(x, y),
7677
}
7778

7879
return (

0 commit comments

Comments
 (0)