Used with a component · SwipeToReveal
useSwipeReveal
The drag engine behind <SwipeToReveal>. You drag a row's content sideways to uncover an actions panel on its leading or trailing edge. A press must move 8 px before it counts as a drag, and a mostly vertical move scrolls the list instead. On release, the row opens or closes based on how fast and how far you dragged. The component adds the action panels, their measured widths, focus handling and the change event.
Install
import { useSwipeReveal } from 'vael-ui'Examples
<script setup lang="ts">
import { ref } from 'vue'
import { useSwipeReveal } from 'vael-ui'
const open = ref(false)
const { offset, onContentPointerdown, onContentClick } = useSwipeReveal(open, {
leadingWidth: 0,
trailingWidth: 96,
})
</script>
<template>
<div class="row">
<div class="row-actions"><button>Delete</button></div>
<div
class="row-content"
:style="{ transform: `translateX(${offset}px)` }"
@pointerdown="onContentPointerdown"
@click.capture="onContentClick"
>
Invoice #1042
</div>
</div>
</template>
<style>
.row { position: relative; overflow: hidden; }
.row-actions { position: absolute; inset-block: 0; inset-inline-end: 0; inline-size: 96px; }
/* pan-y keeps vertical list scrolling native while the row takes horizontal drags. */
.row-content { position: relative; touch-action: pan-y; }
</style>