vael-ui v0.5.7

Forms & inputs

Layout

RadioGroup

A group of Radio options where only one can be selected at a time. Use it for a short list of choices that should all stay visible.

Validating a form? vael-form wires this up with a schema

Install

import { RadioGroup } from 'vael-ui'

Playground

Placement, behaviour and animation

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

const value = ref<string | number | null>(null)
</script>

<template>
  <RadioGroup v-model="value">
    <Radio value="standard" label="Standard shipping" />
    <Radio value="express" label="Express shipping" />
    <Radio value="overnight" label="Overnight shipping" disabled />
  </RadioGroup>
</template>

Props

NameTypeDefaultDescription
namestringNative name shared by every Radio's input. Auto-generated when omitted.
disabledbooleanfalseDisables every Radio in the group.
orientation'horizontal' | 'vertical''vertical'Lays the radios out in a row or a column.
uiPartial<Record<'root', UiPartValue>>Class and style overrides for each part.
motionRadioGroupMotionHow it moves: its appearance ({ initial: { root: { opacity: 0, y: 4 } } }); each Radio keeps its own motion. false turns its own animation off.
modelValuestring | number | nullnullValue of the selected Radio, or null when none is selected.

Events

NameTypeDescription
update:modelValue(value: string | number | null)Fires when modelValue changes (v-model).
change(value: string | number | null)Fires when you select a different Radio, with its value.

Slots

NameTypeDescription
defaultanyThe group's Radio items.

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

RadioGroup: its appearance; its radios keep their own motion.

<RadioGroup
  :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

Follows the Radio Group pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
TabMoves focus into the group, onto the selected radio.
ArrowDownArrowRightSelects the next radio.
ArrowUpArrowLeftSelects the previous radio.
SpaceSelects the focused radio.
  • A div with role="radiogroup" around native radios that share one name, so the browser handles the arrow keys.
  • Inside a Field, the label names the group with aria-labelledby, and the description and error are linked with aria-describedby. Outside one, give it an aria-label.
  • It sets aria-invalid and aria-required from the Field.