Gestures
Layout
Sortable
A list you reorder by dragging or from the keyboard. Use it for any order people set by hand, in one list or across several.
Install
import { Sortable } from 'vael-ui'Playground
- Apple
- Banana
- Cherry
- Date
- Elderberry
Fruits
y
button
card
undefined
Placement, behaviour and animation
Usage
<script setup lang="ts">
import { Sortable } from 'vael-ui'
const items = [
{ label: 'Apple', value: 'apple' },
{ label: 'Banana', value: 'banana' },
{ label: 'Cherry', value: 'cherry' },
]
</script>
<template>
<Sortable :items="items" />
</template>Motion New
Sortable: its appearance, row by row, and states.
<Sortable
:motion="{ states: { dragging: { item: { scale: 1.04 } } } }"
/>| Name | Type | Description |
|---|---|---|
initialexit | rootitem | Sets 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. |
states | draggingsettling | Sets 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) => animation | Animates 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 | string | Times all of it: a spring, or a duration in ms with an easing. Never both. |
false | boolean | Turns its motion off, for an animation of your own on its exposed elements. |
Accessibility
| Key | Action |
|---|---|
| EnterSpace | Picks up the item from its focused handle, or drops the held item. |
| ArrowUpArrowDown | Moves the held item one position, when axis is y. |
| ArrowLeftArrowRight | Moves the held item one position, when axis is x. |
| ArrowLeftArrowRight | Moves the held item to the end of the previous or next list in a group, when axis is y (ArrowUp / ArrowDown when it is x). |
| Escape | Cancels the move and returns the item to where it started, during a keyboard move or a drag. |
| TabShiftTab | Cancels a keyboard move as focus leaves the handle. |
- Each item's handle is a
<button>named bylabelKey, witharia-roledescription="sortable item", andaria-pressedwhile its item is grabbed. Itsaria-describedbypoints at hidden instructions for the keys. Escape cancels a grab or drag without closing a Dialog or Drawer around the list. - An always-mounted
role="status"region witharia-live="polite"announces each grab, move, drop and cancel with the position, such as “Position 2 of 5”. - After a keyboard drop, focus stays on the moved item’s handle. Focus leaving the handle during a keyboard move cancels it. With
disabled, the handles are disabled buttons. - Right to left, ArrowLeft and ArrowRight swap.