Actions
Layout
Button
A button for an action, with variants, sizes, icons and a loading state. Use it for any action, and add hold when a destructive one needs a press and hold to confirm.
Install
import { Button } from 'vael-ui'Playground
primary
undefined
overlay
undefined
Placement, behaviour and animation
button
Usage
<script setup lang="ts">
import { Button } from 'vael-ui'
</script>
<template>
<Button>Button</Button>
</template>Motion New
active is pressed (pointer, Space or Enter); hover responds to a mouse only.
<Button
:motion="{ states: { active: { root: { scale: 1.04 } } } }"
/>| Name | Type | Description |
|---|---|---|
initialexit | rootleadingtrailingcontentlabelbadge | 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 | activehoverfocusloadingdisabled | 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
Follows the Button pattern from the WAI-ARIA Authoring Practices Guide.
| Key | Action |
|---|---|
| EnterSpace | Runs the action. |
- A native
<button>by default. Withasset to a plain tag, such asdivor anawithouthref, it getsrole="button", a Tab stop, and Enter and Space. A link with anhrefstays a link. loadingsetsaria-busyandaria-disabledbut notdisabled, so the button keeps focus. Clicks are ignored while it loads.- An
iconbutton has no visible text: give it anaria-label.v-model:pressedsetsaria-pressed, and the loader and the#leadingand#trailingslots arearia-hidden. - With
hold, holding Enter or Space fills the button and runs the action when the fill completes. Letting go early cancels. A hidden “Press and hold to confirm” hint is linked througharia-describedby.