vael-ui v0.5.7

Actions

Layout

SelectButton

A segmented control that picks one or more values from a short list. Use it instead of radios or checkboxes when every option fits in one row.

Install

import { SelectButton } from 'vael-ui'

Playground

Placement, behaviour and animation

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

const items = [
  { label: 'Apple', value: 'apple' },
  { label: 'Banana', value: 'banana' },
  { label: 'Cherry', value: 'cherry' },
]
const value = ref<string | number | (string | number)[] | null>(null)
</script>

<template>
  <SelectButton :items="items" v-model="value" />
</template>

Props

NameTypeDefaultDescription
itemsRequiredreadonly T[]Options to choose from.
multiplebooleanfalseTurns on multi-select; the model becomes an array.
allowEmptybooleantrueSingle mode only: clicking the active option clears the model.
disabledbooleanfalseDisables every option and blocks interaction.
size'sm' | 'md' | 'lg''md'Control size.
namestringNative name for form submission. Auto-generated when omitted.
uiPartial<Record<'root' | 'option' | 'indicator', UiPartValue>>Class and style overrides for each part.
motionSelectButtonMotionHow it moves: its appearance, option by option ({ initial: { option: { opacity: 0, y: 4 } }, stagger: 0.03 }), over root, option and the selection indicator, and its states ({ states: { disabled: { root: { opacity: 0.6 } } } }). spring retimes the indicator; move hands its moves to your own animation. false turns its own animation off.
modelValuestring | number | (string | number)[] | nullnullSelected value, an array of values with multiple, or null when nothing is selected.

Events

NameTypeDescription
change(value: string | number | (string | number)[] | null)Fires when you change the selection, with the new model value.
update:modelValue(value: string | number | (string | number)[] | null)Fires when modelValue changes (v-model).

Slots

NameTypeDescription
item{ item: T; checked: boolean; }Custom content for each option. Receives item and checked.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
indicatorElHTMLElement | nullSliding selection indicator (single mode only; null with multiple).
highlightElHTMLElement | nullThe hover and keyboard highlight, sliding between options. Under a ConfigProvider with motion: false it moves at once, for your own animation.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

SelectButton: its appearance, and how the selection moves.

<SelectButton
  :motion="{ states: { disabled: { root: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitrootoptionindicatorSets 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.
statesdisabledSets 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.
move(parts, context) => animationMoves its sliding indicator. A spring retimes it, and a move hook animates it with your own library, starting from context.from.
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 Radio Group pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
TabMoves focus into the group and out of it.
ArrowRightArrowDownArrowLeftArrowUpMoves to and selects the next or previous option (single choice).
SpaceSelects the focused option, or toggles it with multiple.
  • Built on native inputs: radios inside role="radiogroup", or checkboxes inside role="group" with multiple. The browser handles the keys.
  • Give the group a name: wrap it in a Field, or pass aria-label. A Field also sets aria-invalid and aria-required on it.
  • Each option’s label is its accessible name. The sliding highlight is aria-hidden.