-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[🐞] onDblClick$
doesn't handle double tap
#7197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
None of the events do special handling, they're mapping to the browser events, so normally you would create the qrl separately and assign it to onDblTap$ as well. Another thing Qwik doesn't do is change onChange to be onInput, like React does. So I'm thinking this is working as expected? |
well, I changed it to onDblTap$ as you said and it didn't work... now it doesn't work on double tap neither double click. |
the test I did is available on the stackblitz reproduction that I've linked maybe I'm calling it wrong? idk |
I'd like to document here if someone else find in the same trouble that I could workaround it creating a custom hook import type { QRL } from "@builder.io/qwik";
import { $, useSignal } from "@builder.io/qwik";
/**
* Custom hook to handle both double-click and single-click events.
* This is particularly useful for handling double-tap events on mobile devices,
* which are currently not supported by Qwik's native onDblClick$ handler.
* @see {@link https://github.com/QwikDev/qwik/issues/7197 GitHub issue tracking onDblClick$ mobile support}
*
* @param onDoubleClick - Handler function to be called when a double-click is detected
* @param onSingleClick - Optional handler function to be called when a single-click is detected
* @param threshold - Time in milliseconds to wait for a second click (default: 300ms)
*
* @returns A QRL function that can be directly used with onClick$
*
* @example
* ```tsx
* export const MyComponent = component$(() => {
* const onClick$ = useDoubleClick(
* $(() => console.log('Double clicked!')),
* $(() => console.log('Single clicked!'))
* );
*
* return <button onClick$={onClick$}>Click me</button>;
* });
* ```
*/
export const useDoubleClick = (
onDoubleClick: QRL<() => void>,
onSingleClick?: QRL<() => void>,
threshold = 300
) => {
const lastClick = useSignal(0);
return $(() => {
const currentTime = new Date().getTime();
const timeDiff = currentTime - lastClick.value;
if (timeDiff < threshold) {
onDoubleClick();
lastClick.value = 0;
} else {
lastClick.value = currentTime;
if (onSingleClick) {
setTimeout(() => {
if (lastClick.value === currentTime) {
onSingleClick();
}
}, threshold);
}
}
});
}; |
Which component is affected?
Qwik Runtime
Describe the bug
onDblClick$
event handler doesn't handle double tap, making it useless on mobile devices.on the other hand,
onClick$
handle clicks and taps.Reproduction
https://stackblitz.com/edit/github-vk5focuq?file=src%2Froutes%2Findex.tsx
Steps to reproduce
with the reproduction from stackblitz that I gave, open the preview in a new tab, and then:
System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: