Mutually exclusive plans
Choose one subscription plan and submit its scalar value.
Components / Forms
Native radios grouped by a fieldset and legend.
Last changed in version 0.14.2: Improve keyboard navigation, action feedback, and selected colors across Vue components.
bunx --bun @getweini/cli@latest add radio-groupImport the files copied by the install command, then place the component in your Vue template. The text and values in the example belong to your app; change them to fit your task.
<script setup lang="ts">
import { ref } from 'vue'
import RadioGroup from './components/ui/radio-group/RadioGroup.vue'
import RadioGroupItem from './components/ui/radio-group/RadioGroupItem.vue'
const plan = ref<string | number>('personal')
</script>
<template>
<RadioGroup v-model="plan" name="plan">
<template #legend>Plan</template>
<RadioGroupItem value="personal">Personal</RadioGroupItem>
<RadioGroupItem value="team">Team</RadioGroupItem>
</RadioGroup>
</template>RadioGroupItem must be inside RadioGroup. Use the legend slot to name the group.
Choose one subscription plan and submit its scalar value.
Show two short choices in a horizontal fieldset.
The legend names the native radio fieldset.
<script setup lang="ts">
import { ref } from 'vue'
import RadioGroup from './components/ui/radio-group/RadioGroup.vue'
import Radio from './components/ui/radio-group/RadioGroupItem.vue'
const plan = ref<string | number>('monthly')
</script>
<template>
<RadioGroup v-model="plan" name="plan" required>
<template #legend>Billing plan</template>
<Radio value="monthly">Monthly</Radio>
<Radio value="annual">Annual</Radio>
</RadioGroup>
</template>Orientation changes layout while native radio behavior stays intact.
<script setup lang="ts">
import { ref } from 'vue'
import RadioGroup from './components/ui/radio-group/RadioGroup.vue'
import Radio from './components/ui/radio-group/RadioGroupItem.vue'
const speed = ref<string | number>('standard')
</script>
<template>
<RadioGroup v-model="speed" name="delivery" orientation="horizontal">
<template #legend>Delivery speed</template>
<Radio value="standard">Standard</Radio>
<Radio value="express">Express</Radio>
</RadioGroup>
</template>Every public prop, model, event, slot, and exposed member of the installed Vue parts is listed below. “Not set” means you can leave that value out; “Required” means you must provide it. Native HTML attributes also work where the component uses a native element.
| Name | Type or signature | Default | What it does |
|---|---|---|---|
valueprop | string | number | Required | Value represented by this control or option. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
idprop | string | undefined | Not set | Give the control an ID so a label or description can refer to it. |
defaultslot | () => unknown | Required | Content shown inside Radio. |
elementexposed | HTMLInputElement | null | — | Reference to the underlying HTML element. |
focusexposed | () => void | undefined | — | Move keyboard focus to this control. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
nameprop | string | undefined | Not set | Name used when this control submits a value with a form. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
requiredprop | boolean | undefined | Not set | Ask the browser to require a value before form submission. |
invalidprop | boolean | undefined | Not set | Show the invalid state; also provide a visible error message. |
orientationprop | "horizontal" | "vertical" | undefined | "vertical" | Arrange items horizontally or vertically. |
formprop | string | undefined | Not set | Associate the control with a form by its ID. |
modelValuemodel | string | number | undefined | Not set | Current value. Use v-model to keep it in sync with your page. |
update:modelValueevent | [value: string | number | undefined] | — | Requests a new model value from the parent. |
defaultslot | () => unknown | Required | Content shown inside RadioGroup. |
legendslot | () => unknown | Required | Content for the legend area of RadioGroup. |
errorslot | ((props: { message: string; messages: string[]; }) => unknown) | undefined | Optional | Content for the error area of RadioGroup. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
valueprop | string | number | Required | Value represented by this control or option. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
idprop | string | undefined | Not set | Give the control an ID so a label or description can refer to it. |
defaultslot | () => unknown | Required | Content shown inside RadioGroupItem. |
elementexposed | HTMLInputElement | null | — | Reference to the underlying HTML element. |
focusexposed | () => void | undefined | — | Move keyboard focus to this control. |
// packages/frameworks/vue/components/radio-group/types.ts
// ------- TYPES -------
export interface RadioGroupProps {
name?: string
disabled?: boolean
required?: boolean
invalid?: boolean
orientation?: 'horizontal' | 'vertical'
form?: string
}
export interface RadioProps {
value: string | number
disabled?: boolean
id?: string
}