Used with a component · BottomSheet
useSheetDrag
The drag and snap engine behind <BottomSheet>. The panel stays as tall as its area and moves only with translateY, so a drag never resizes it. A release settles on a snap point, steps one point after a short, quick flick, or calls onDismiss. It judges the speed over the last 80 ms, so a slow drag that ends in a flick counts as a flick. A drag on the content moves the sheet only when the content is scrolled to the top and the drag goes down. <BottomSheet> adds the overlay, the focus trap, enter and exit, the close flow and nested sheet detection.
Install
import { useSheetDrag } from 'vael-ui'Examples
<script setup lang="ts">
import { shallowRef, useTemplateRef } from 'vue'
import { useSheetDrag } from 'vael-ui'
const open = shallowRef(true)
const panel = useTemplateRef<HTMLElement>('panel')
const handle = useTemplateRef<HTMLElement>('handle')
const content = useTemplateRef<HTMLElement>('content')
const { activeSnap, isDragging } = useSheetDrag(open, {
panelEl: panel,
handleEl: handle,
contentEl: content,
snapPoints: [
{ id: 'peek', height: 0.35 },
{ id: 'full', height: 0.9 },
],
initialSnap: 'peek',
onDismiss: () => (open.value = false),
})
</script>
<template>
<div
v-if="open"
ref="panel"
class="sheet"
:data-snap="activeSnap"
:data-dragging="isDragging || undefined"
>
<div ref="handle" class="handle" />
<div ref="content" class="content">Drag the handle, or flick down to dismiss.</div>
</div>
</template>
<style scoped>
/* As tall as the largest snap point: the composable only moves it with translateY. */
.sheet {
position: fixed;
inset: auto 0 0;
height: 90dvh;
border-radius: 16px 16px 0 0;
background: var(--ui-surface);
}
.handle {
height: 24px;
cursor: grab;
touch-action: none;
}
</style>