Skip to content

Radio

Overview

The Radio component provides an interface for selecting one option from a set of mutually exclusive options. This component is designed for customization and offers several configurations for rendering the radio button and its associated label.

Storybook

Props

PropTypeDefaultDescription
modelValueString''The value that is bound to the radio component.
valueString''The value of the radio input.
labelString''Label text for the radio input.
inputClassString''Class to be applied to the radio input.
colorString'primary'Color theme for the radio button. This can be primary, secondary, warning, etc.
nameString''Name attribute for the radio input. Used to group multiple radio buttons.
idString''ID attribute for the radio input.
labelClassString''Class to be applied to the label.
wrapperClassString''Class to be applied to the component wrapper.
hideErrorBooleanfalseIf true, hides the error message.
disabledBooleanfalseIf true, the radio input is disabled.
errorClassString''Class to be applied when the input is in an error state.
hintString''Hint or help text displayed below the input.
errorMessageString''Error message displayed when the input is in an error state.
groupClassString''Class to be applied to the radio group wrapper.

Events

EventPayload TypeDescription
update:modelValueRadioValueEmits the current value of the radio component.

Slots

SlotPropsDescription
default{}Default slot for additional content.
hint{}Custom hint content. If not provided, the hint prop will be used.
error{}Custom error content. If not provided, the errorMessage prop will be used.

Usage

To use the Radio component:

  1. Import the component.
  2. Bind the necessary props.
  3. Optionally, use the slots for custom content.
vue
<script setup lang="ts">
import {ref} from 'vue';
import Radio from '@morpheme/forms';

const selectedOption = ref('');
const radioValue = 'option1';
</script>

<template>
  <Radio
    v-model="selectedOption"
    :value="radioValue"
    label="Option 1"
    name="radioGroup"
  />
</template>
<script setup lang="ts">
import {ref} from 'vue';
import Radio from '@morpheme/forms';

const selectedOption = ref('');
const radioValue = 'option1';
</script>

<template>
  <Radio
    v-model="selectedOption"
    :value="radioValue"
    label="Option 1"
    name="radioGroup"
  />
</template>

This will render a radio button with the label "Option 1". The value of the selected radio button will be bound to the selectedOption ref.