Radio
A Radio Button is a component that enables a user to select a single option from a set of choices.
Basic Usage
vue
<template>
<div class="spr-flex spr-flex-col spr-items-start spr-gap-2">
<spr-radio id="radio1" v-model="radioModel" name="radio_name" value="value1">Radio Label 1</spr-radio>
<spr-radio id="radio2" v-model="radioModel" name="radio_name" value="value2">Radio Label 2</spr-radio>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
const radioModel = ref('');
</script>
Active
vue
<template>
<spr-radio id="radio1" v-model="radioModel" name="radio_name" value="value1">Radio Label 1</spr-radio>
<spr-radio id="radio2" v-model="radioModel" name="radio_name" value="value2">Radio Label 2</spr-radio>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
const radioModel = ref('value2');
</script>
Disabled
Add the disabled
attribute to the <spr-radio>
component to disable the radio button.
vue
<template>
<div class="spr-flex spr-flex-col spr-items-start spr-gap-2">
<spr-radio id="disabledradio1" v-model="radioModel" name="radio_name" value="value1">Radio Label 1</spr-radio>
<spr-radio id="disabledradio2" v-model="radioModel" name="radio_name" value="value2" disabled>
Radio Label 2
</spr-radio>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
const radioModel = ref('');
</script>
API Reference
Props
Name | Description | Type | Default |
---|---|---|---|
id | Unique identifier for the radio input element. Required for accessibility and label association. | string | Required |
modelValue | Current selected value used with v-model for two-way binding. When this matches the radio's value prop, the radio is selected. | string | number | boolean | undefined |
name | Name attribute for the radio input element. Radio buttons in the same group should share the same name to ensure only one can be selected at a time. | string | Required |
value | The value associated with this radio button. When the radio is selected, this value is assigned to the modelValue . | string | number | boolean | Required |
disabled | When set to true , the radio button becomes non-interactive and appears visually disabled. Users cannot select a disabled radio button. | boolean | false |
description | Additional explanatory text displayed below the radio label to provide more context or details about this option. | string | undefined |
bordered | When set to true , adds a border around the entire radio component (including the label), providing visual separation from surrounding elements. | boolean | false |
fullWidth | When set to true , the radio component will stretch to fill the full width of its container. When false , it will only be as wide as its content. | boolean | false |
Events
Name | Description | Parameters |
---|---|---|
update:modelValue | Emitted when the radio button is selected. This event is used for v-model binding to work correctly. | (value: string | number | boolean) - The value of the selected radio button |
Slots
Name | Description |
---|---|
default | Content to be displayed as the radio button's label. This typically contains text but can include other elements for more complex labels. |
Animation
Animation | Description |
---|---|
animate-shadow-grow | Applied when the radio button is selected, creating a smooth transition from an empty circle to a filled circle with a white center. |