vael-ui v0.5.7

Actions

Layout

ButtonGroup

A connected row or column of buttons that can also work as single or multiple toggles. Use it for related actions or options that belong together.

Install

import { ButtonGroup } from 'vael-ui'

Playground

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { ButtonGroup, Button } from 'vael-ui'

const value = ref<ButtonGroupValue | readonly ButtonGroupValue[] | null>()
</script>

<template>
  <ButtonGroup v-model="value">
    <Button variant="outline">Archive</Button>
    <Button variant="outline">Report</Button>
    <Button variant="outline">Snooze</Button>
  </ButtonGroup>
</template>

Props

NameTypeDefaultDescription
orientation'horizontal' | 'vertical''horizontal'Whether the buttons sit in a row or a column.
ariaLabelstringAccessible name for the group.
multiplebooleanfalseWith v-model: several buttons can be on at once, and the model is an array of their values. Otherwise one at a time.
allowEmptybooleantrueWith v-model, one at a time: clicking the button that's on turns it off. Set false for a choice that always has one (text alignment).
motionButtonGroupMotionHow it moves: its appearance ({ initial: { root: { opacity: 0, y: 4 } } }); its buttons keep their own motion. false turns its own animation off.
uiPartial<Record<'root', UiPartValue>>Class and style overrides for each part.
modelValueButtonGroupValue | readonly ButtonGroupValue[] | nullOpt-in toggles. Bind it, and every Button inside with a value turns on and off, with aria-pressed set for you: one value at a time, or an array with multiple. Unbound, the group is purely visual, as before.

Events

NameTypeDescription
update:modelValue(value: ButtonGroupValue | readonly ButtonGroupValue[] | null | undefined)Fires when modelValue changes (v-model).

Slots

NameTypeDescription
defaultanyThe grouped buttons.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

ButtonGroup: its appearance; its buttons keep their own motion.

<ButtonGroup
  :motion="{ initial: { root: { opacity: 0, y: 4 } } }"
/>
NameTypeDescription
initialexitrootSets 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.
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

KeyAction
TabShiftTabMoves between the buttons; each one is its own Tab stop.
EnterSpaceRuns or toggles the focused button.
  • Renders role="group". Pass aria-label to name the group.
  • With v-model, every Button inside that has a value becomes a toggle and gets aria-pressed. Without it, the group only joins the buttons visually.