Replace long press with tap target

This commit is contained in:
Jon Staab
2025-03-03 13:59:38 -08:00
parent 5bba5959f7
commit b399fa8dcc
4 changed files with 24 additions and 38 deletions
-29
View File
@@ -1,29 +0,0 @@
<script lang="ts">
const {children, onLongPress, ...restProps} = $props()
const ontouchstart = (event: any) => {
touch = event.touches[0]
timeout = setTimeout(onLongPress, 500)
}
const ontouchmove = (event: any) => {
const curTouch = event.touches[0]
if (Math.abs(curTouch.clientX - touch.clientX) > 30) {
clearTimeout(timeout)
}
if (Math.abs(curTouch.clientY - touch.clientY) > 30) {
clearTimeout(timeout)
}
}
const ontouchend = () => clearTimeout(timeout)
let touch: Touch
let timeout: any
</script>
<div role="button" tabindex="0" {ontouchstart} {ontouchmove} {ontouchend} {...restProps}>
{@render children()}
</div>
+15
View File
@@ -0,0 +1,15 @@
<script lang="ts">
import {isMobile} from "@lib/html"
const {children, onTap, ...restProps} = $props()
const onclick = (event: MouseEvent) => {
if (isMobile) {
onTap(event)
}
}
</script>
<div role="button" tabindex="0" {onclick} {...restProps}>
{@render children()}
</div>