useDragResizer

Commons
stable

Attaches mouse and touch drag listeners to a DOM element so the user can resize a panel or split view. Clamps the resulting value between min and max, supports both horizontal (X) and vertical (Y) axes, and cleans up all event listeners on unmount.

API

Signature

Full TypeScript signature sourced from the composable file.

typescript

useDragResizer registers useEventListener internally and calls onUnmounted to clean up all window listeners. Pass the handle element after mount (e.g. inside onMounted) to guarantee the ref is resolved.

API

Parameters

Input parameters accepted by this composable.

el
required
MaybeRef<HTMLElement | undefined>
The handle element that should receive the mousedown/touchstart listeners. Pass undefined to skip registration (e.g. when the element is not yet mounted).
value
required
Ref<number>
Reactive number representing the current size of the resizable panel. Updated in real-time while dragging.
min
required
MaybeRefOrGetter<number>
Minimum allowed value in pixels. The drag is clamped so value never goes below this.
max
required
MaybeRefOrGetter<number>
Maximum allowed value in pixels. The drag is clamped so value never exceeds this.
axis
required
TAxis
Drag axis. Use AXIS.X for horizontal resizing (e.g. left/right panels) and AXIS.Y for vertical resizing (e.g. top/bottom splits).

Usage

Examples

Ready-to-paste usage snippets.

Horizontal panel resizer

vue