Used with a component · Resizable
useResizable
The headless drag and keyboard engine behind <Resizable>. It turns a handle's pointer drag into a size in px on your ref, written once a frame. Mid drag, the size stretches past min and max with rubber-band resistance, then settles back within them on release. Escape puts it back where the drag started. Arrow keys resize by 16 px, and Home and End jump to min and max. <Resizable> adds the panel, the separator role and its ARIA values. Use the composable when the handle and the panel live apart in your own layout. A window that pulls both ways takes a pair of sizes, useResizable({ horizontal: width, vertical: height }, { horizontal: { min: 240 }, vertical: { min: 140 } }), and each handle names where it sits: onHandlePointerdown(event, 'se'). A side pulls one axis and a corner pulls both, and onCommit fires once per release.
Install
import { useResizable } from 'vael-ui'Examples
<script setup lang="ts">
import { ref } from 'vue'
import { useResizable } from 'vael-ui'
const width = ref(240)
const { isDragging, onHandlePointerdown, onHandleKeydown } = useResizable(width, {
min: 160,
max: 480,
})
</script>
<template>
<aside class="sidebar" :style="{ inlineSize: `${width}px` }">
<nav>...</nav>
<div
class="sidebar-handle"
role="separator"
aria-orientation="vertical"
aria-label="Resize sidebar"
tabindex="0"
:aria-valuenow="Math.round(width)"
aria-valuemin="160"
aria-valuemax="480"
:data-active="isDragging || undefined"
@pointerdown="onHandlePointerdown"
@keydown="onHandleKeydown"
/>
</aside>
</template>