Skip to content

Commit 4c599d2

Browse files
author
pac-guerreiro
committed
fix: tooltip component not working with non pressable components
1 parent b5d6715 commit 4c599d2

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,15 @@ const Tooltip = ({
123123
clearTimeout(hideTooltipTimer.current);
124124
}
125125

126-
showTooltipTimer.current = setTimeout(() => {
126+
if (isWeb) {
127+
showTooltipTimer.current = setTimeout(() => {
128+
touched.current = true;
129+
setVisible(true);
130+
}, enterTouchDelay) as unknown as NodeJS.Timeout;
131+
} else {
127132
touched.current = true;
128133
setVisible(true);
129-
}, enterTouchDelay) as unknown as NodeJS.Timeout;
134+
}
130135
};
131136

132137
const handleTouchEnd = () => {
@@ -149,6 +154,9 @@ const Tooltip = ({
149154
return children.props.onPress?.();
150155
}
151156
}, [children.props]),
157+
onLongPress: () => handleTouchStart(),
158+
onPressOut: () => handleTouchEnd(),
159+
delayLongPress: enterTouchDelay,
152160
};
153161

154162
const webPressProps = {
@@ -193,17 +201,16 @@ const Tooltip = ({
193201
</View>
194202
</Portal>
195203
)}
196-
<View
197-
onTouchStart={handleTouchStart}
198-
onTouchEnd={handleTouchEnd}
199-
onTouchCancel={handleTouchEnd}
204+
<Pressable
205+
ref={childrenWrapperRef}
206+
style={isWeb ? styles.webContainer : null}
207+
{...(isWeb ? webPressProps : mobilePressProps)}
200208
>
201209
{React.cloneElement(children, {
202210
...rest,
203-
ref: childrenWrapperRef,
204211
...(isWeb ? webPressProps : mobilePressProps),
205212
})}
206-
</View>
213+
</Pressable>
207214
</>
208215
);
209216
};
@@ -222,6 +229,9 @@ const styles = StyleSheet.create({
222229
hidden: {
223230
opacity: 0,
224231
},
232+
webContainer: {
233+
cursor: 'default',
234+
} as ViewStyle,
225235
});
226236

227237
export default Tooltip;

0 commit comments

Comments
 (0)