vael-ui v0.5.7

Layout & structure

Layout

Resizable

A drag handle that resizes a panel between a minimum and a maximum size. Use it for sidebars and split views.

This site’s sidebar is built with Resizable. Drag its right edge to try it.

Install

import { Resizable } from 'vael-ui'

Playground

Drag the handle

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { Resizable } from 'vael-ui'
</script>

<template>
  <Resizable :min="120" :max="280" :size="200">Drag the handle</Resizable>
</template>

Props

NameTypeDefaultDescription
minnumber0Smallest size in pixels.
maxnumberInfinityLargest size in pixels.
direction'horizontal' | 'vertical''horizontal'Axis the panel resizes along: 'horizontal' sets its width, 'vertical' its height.
edge'start' | 'end' | 'both''end'Which edge the handle sits on. 'start' flips the drag so moving toward the panel grows it. 'both' puts a handle on each edge, and pulling one moves only that side: the far end stays put. Add v-model:offset to give the start a position of your own, for a span.
centeredbooleanfalseResizes from the middle: the handle you pull follows the pointer and the opposite edge moves as far the other way, so the panel's centre stays put.
bounds[number, number]With offset: the span stays between these, start and end, in pixels.
scrollElHTMLElement | nullA scrolling container: near its edges it scrolls under the pointer during a drag, and the drag follows. Its scroll-padding marks what covers it, such as a sticky column.
movablebooleantrue with `offset`With offset: press on the panel and drag to move the whole span, and the arrow keys move it a step. A still press stays a click. Set false to resize only.
stepnumberSnaps the size to a multiple of step on release, the drag itself staying smooth, and an arrow key resizes one step. Unset, a drag doesn't snap and an arrow key moves 16 px.
disabledbooleanfalseDisables dragging and keyboard resizing, and removes the handle from the tab order.
ariaLabelstring'Resize'Accessible label for the handle. With edge="both" the labels are the messages' start and end.
motionResizableMotionHow it moves: its appearance ({ initial: { root: { opacity: 0 } } }) and its states ({ states: { dragging: { handle: { scale: '1.2' } } } }). false turns its own animation off.
uiPartial<Record<'root' | 'handle', UiPartValue>>Class and style overrides for each part.
sizeRequirednumberPanel size in pixels along direction. Overshoots min or max elastically mid-drag, then settles within them.
offsetnumberWhere a span starts, in pixels along direction, for a bar on a timeline: bind it and the panel positions itself from this start (give its container position: relative). A handle on the start edge moves the start and the size together, so the far end stays put. Bind it from the start; it isn't read as a span if it begins unset.

Events

NameTypeDescription
commit()Fires once per settled interaction: on pointer release, or after each key press. Save here instead of on every drag frame.
update:size(value: number)Fires when size changes (v-model:size).
update:offset(value: number | undefined)Fires when offset changes (v-model:offset).

Slots

NameTypeDescription
defaultanyPanel content.
handle{ edge: ResizeEdge; }Custom content inside a drag handle; edge says which when there are two.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
handleElHTMLElement | nullDrag handle element.
isDraggingbooleanWhether you're dragging the handle with a pointer.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Resizable: its appearance and states.

<Resizable
  :motion="{ states: { dragging: { root: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitroothandleSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
statesdraggingSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Window Splitter pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
ArrowLeftArrowRightMoves the handle 16 px and resizes the panel, when direction is horizontal.
ArrowUpArrowDownMoves the handle 16 px and resizes the panel, when direction is vertical.
HomeSets the panel to its min size.
EndSets the panel to its max size, when max is set.
  • The handle has role="separator" and is a Tab stop. With disabled, it leaves the tab order.
  • It sets aria-valuenow to the size in pixels and aria-valuemin to min. aria-valuemax is max, or the room its container gives it when there’s no max.
  • The handle is named “Resize” by default (the resizable.label message). Pass aria-label to say which panel it resizes.
  • With edge="both" there are two handles, named “Resize start” and “Resize end” (the resizable.start and resizable.end messages). With v-model:offset the panel itself is a Tab stop: the arrow keys move the whole span a step.
  • Right to left, ArrowLeft and ArrowRight swap.