Radio Group
Choose one option from a group.
Demos
Size
Framework
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Installation
Complete the shared installation. Copy RadioGroup.vue and index.ts into app/components/ui/radio-group/.
app/components/ui/radio-group/RadioGroup.vue
<script setup lang="ts">
import { AlertDialog as Primitive } from 'akaza-ui'
import { computed, useAttrs, useTemplateRef } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
alertDialogVariants,
resolveAlertDialogVariants,
type AlertDialogProps,
type AlertDialogSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AlertDialogProps>(), {
as: undefined,
teleport: undefined,
transition: undefined,
duration: undefined,
title: undefined,
ariaLabel: undefined,
description: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AlertDialogSlots>()
const attrs = useAttrs()
const styles = computed(() => alertDialogVariants(resolveAlertDialogVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'content' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, width: _width, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
defineExpose({
get open() {
return primitive.value!.open
},
get close() {
return primitive.value!.close
},
get toggle() {
return primitive.value!.toggle
},
get titleId() {
return primitive.value!.titleId
},
get descriptionId() {
return primitive.value!.descriptionId
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AlertDialogSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
Radio Group uses 8, 10, 12, 14, and 16px spacing for xs through xl. Selection fades and scales the inner dot over 180ms; reduced motion disables the transition.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | any[] | — | Required. Array of option values or objects. |
valueKey | string | — | Property to use as the value when options are objects. |
labelKey | string | "label" | Property to use as the display label. |
descriptionKey | string | "description" | Property to use as the description text. |
disabled | boolean | false | Disable all options. |
orientation | "horizontal" | "vertical" | "vertical" | Layout direction. |
legend | string | — | Visible group label. Slot #legend takes priority. |
loop | boolean | true | Wrap arrow key navigation at the ends. |
name | string | — | HTML name for form submission. |
required | boolean | false | Marks the group as required. |
ariaLabel | string | — | aria-label on the group element. |
ariaLabelledby | string | — | aria-labelledby on the group element. |
getItemDisabled | (option: any) => boolean | — | Function to disable individual options. |
as | string | "div" | Root element tag. |
ui | RadioGroupUi | — | CSS class overrides. |
Slots
| Slot | Scoped props | Description |
|---|---|---|
legend | { legend } | Group label. Defaults to the legend prop. |
item | { option, value, label, description, isChecked, isDisabled, select } | Each radio option. |
Events
| Event | Payload | Description |
|---|---|---|
value-change | [value: string, details] | Fired when selected value changes. |
Keyboard
| Key | Behavior |
|---|---|
ArrowUp / ArrowDown | Selects and focuses previous/next enabled item in vertical groups. |
ArrowLeft / ArrowRight | Selects and focuses previous/next enabled item in horizontal groups. |
Home / End | Selects and focuses first or last enabled item. |
Space | Selects focused radio. |
Tab | Enters group at selected item, or first enabled item. |
Arrow navigation wraps when loop is true and skips disabled items.