Touch devices handle taps differently: iOS often requires a second tap to fire a click event (allowing a tooltip to be seen first), while Android fires the click event immediately.
To manage this, you can use tippy.currentInput.isTouch to detect if the user is currently using touch input. This is a dynamic property that changes based on the user's current input method (useful for hybrid devices).
Strategies:
- Make iOS behave like Android (Single tap to click): Trigger a manual
.click() on the element inside the onShow lifecycle hook if the platform is detected as iOS. - Make Android behave like iOS (Double tap to click): Wrap your click listener in a function that requires two clicks (or detects non-touch input) before executing the logic.
// Detecting iOS
const isIOS = /iPhone|iPad|iPod/.test(navigator.platform);
// Strategy A: Single tap to click on iOS
tippy(button, {
onShow() {
if (isIOS) {
button.click();
}
},
});
// Strategy B: Emulate iOS double-tap behavior on Android/Touch
function emulateIOS(listener) {
let clicks = 0;
return function () {
clicks++;
if (clicks === 2 || isIOS || !tippy.currentInput.isTouch) {
clicks = 0;
listener.apply(this, arguments);
}
};
}