Radio Group
Neobrutalist-styled radio group built on reka-ui's RadioGroup primitive, used for single selection.
Demo
自定义 aria-label
Installation
pnpm dlx brutx-vue@latest add radio-groupUsage
<script setup>
import { ref } from 'vue'
import { RadioGroup, RadioGroupItem, Label } from 'brutx-ui-vue'
const selected = ref('comfortable')
</script>
<template>
<RadioGroup v-model="selected">
<div class="flex items-center gap-3">
<RadioGroupItem value="default" />
<Label for="default">Default</Label>
</div>
<div class="flex items-center gap-3">
<RadioGroupItem value="comfortable" />
<Label for="comfortable">Comfortable</Label>
</div>
<div class="flex items-center gap-3">
<RadioGroupItem value="compact" />
<Label for="compact">Compact</Label>
</div>
</RadioGroup>
</template>Accessibility Label
Provide a readable name for the radio group via ariaLabel, making it easier for screen readers to identify the group's purpose. This is especially useful when there is no visible group heading (such as a Label or fieldset legend).
<script setup>
import { ref } from 'vue'
import { RadioGroup, RadioGroupItem } from 'brutx-ui-vue'
const density = ref('comfortable')
</script>
<template>
<RadioGroup v-model="density" aria-label="Layout density">
<div class="flex items-center gap-3">
<RadioGroupItem value="default" />
<span class="text-sm font-bold">Default</span>
</div>
<div class="flex items-center gap-3">
<RadioGroupItem value="comfortable" />
<span class="text-sm font-bold">Comfortable</span>
</div>
<div class="flex items-center gap-3">
<RadioGroupItem value="compact" />
<span class="text-sm font-bold">Compact</span>
</div>
</RadioGroup>
</template>Variants
| Variant | Description |
|---|---|
default | Default style, uses Primary (coral) background when selected |
secondary | Uses Secondary background when selected |
accent | Uses Accent background when selected |
success | Uses Success background when selected |
danger | Uses Danger background when selected |
<template>
<RadioGroupItem value="option" variant="danger" />
</template>Sizes
| Size | Description |
|---|---|
sm | Small (20 x 20) |
default | Default (24 x 24) |
lg | Large (28 x 28) |
Sub-components
| Component | Description |
|---|---|
RadioGroup | Root container, manages selected state and keyboard navigation |
RadioGroupItem | Radio option, each option corresponds to a selectable value |
API Reference
RadioGroup
| Name | Type | Default | Description |
|---|---|---|---|
modelValue | string | undefined | — | The currently selected string value, synchronized through a controlled v-model. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroup.vue | |||
name | string | undefined | — | The form field name passed to the radio-group primitive. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroup.vue | |||
disabled | boolean | undefined | — | Disables every radio item in the group. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroup.vue | |||
orientation | "vertical" | "horizontal" | undefined | — | Sets item layout: vertical stacks items, while horizontal lays them out with wrapping; vertical is the default. |
DetailsDeclared type"vertical" | "horizontal" | undefined Literal values
Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroup.vue | |||
class | string | undefined | — | Additional CSS classes applied to the radio-group root container. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroup.vue | |||
ariaLabel | string | undefined | — | Provides an accessible name for the whole radio group. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroup.vue | |||
| Name | Signature or type | Description |
|---|---|---|
@update:modelValue | [value: string] | Emits the new string value when the selection changes so v-model can be synchronized. |
DetailsDeclared type[value: string] Sourcepackages/ui/src/components/radio-group/RadioGroup.vue | ||
| Name | Signature or type | Description |
|---|---|---|
#default | {} | Contains the RadioGroupItem options belonging to this group. |
DetailsDeclared type{}Sourcepackages/ui/src/components/radio-group/RadioGroup.vue | ||
RadioGroupItem
| Name | Type | Default | Description |
|---|---|---|---|
valueRequired | string | — | The string value represented by this option; when selected, it becomes the RadioGroup modelValue. |
DetailsDeclared typestring Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroupItem.vue | |||
disabled | boolean | undefined | false | Disables this option while leaving other enabled options in the group interactive. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroupItem.vue | |||
class | string | undefined | undefined | Additional CSS classes applied to the radio option button. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroupItem.vue | |||
variant | "accent" | "danger" | "default" | "secondary" | "success" | undefined | "default" | Sets the color variant of the radio option and its selected indicator. |
DetailsDeclared typeNonNullable<"default" | "secondary" | "success" | "danger" | "accent" | null | undefined> | undefined Literal values
Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroupItem.vue | |||
size | "default" | "lg" | "sm" | undefined | "default" | Sets the size of the radio button and selected indicator icon. |
DetailsDeclared typeNonNullable<"default" | "lg" | "sm" | null | undefined> | undefined Literal values
Default value details
Sourcepackages/ui/src/components/radio-group/RadioGroupItem.vue | |||
Accessibility
- Keyboard: Arrow keys navigate between radio options, Space key selects the currently focused option
- ARIA attributes: Selected option uses
aria-checked="true", supports providing a readable group name viaariaLabel - Focus management:
Tabkey focuses the selected option or the first option, arrow keys cycle focus between options