Skip to content

Radio ​

Radio component encapsulation, works better with z-form component.

Basic Usage ​

Pass in options to automatically generate options

<!-- eslint-disable no-console -->
<script lang="ts" setup>
import { ref } from 'vue'

const options = ref([
  { label: 'Option 1', value: 1 },
  { label: 'Option 2', value: 2 },
  { label: 'Option 3', value: 3 },
])

const radioVal = ref(1)

function handleRadioChange(val: number) {
  console.log('radio change:', val)
}
</script>

<template>
  <z-radio v-model="radioVal" :options="options" @change="handleRadioChange" />
</template>

Disabled ​

Set disabled to true for a certain item in option

<script lang="ts" setup>
import { ref } from 'vue'

const options = ref([
  { label: 'Option 1', value: 1 },
  { label: 'Option 2', value: 2, disabled: true },
  { label: 'Option 3', value: 3 },
])

const radioVal = ref(1)
</script>

<template>
  <z-radio v-model="radioVal" :options="options" />
</template>

Disable all, pass disabled as true to the component

<script lang="ts" setup>
import { ref } from 'vue'

const options = ref([
  { label: 'Option 1', value: 1 },
  { label: 'Option 2', value: 2 },
  { label: 'Option 3', value: 3 },
])

const radioVal = ref(1)
</script>

<template>
  <z-radio v-model="radioVal" :disabled="true" :options="options" />
</template>

Key-Value Configuration ​

<script lang="ts" setup>
import { ref } from 'vue'

const options = ref([
  { data: { title: 'Option 1' }, key: 1 },
  { data: { title: 'Option 2' }, key: 2 },
  { data: { title: 'Option 3' }, key: 3 },
])

const alias = {
  label: 'data.title',
  value: 'key',
}

const radioVal = ref(1)
</script>

<template>
  <z-radio v-model="radioVal" :alias="alias" :options="options" />
</template>

Cancel Selection ​

Configure isCancel to true to cancel selection

<script lang="ts" setup>
import { ref } from 'vue'

const options = ref([
  { label: 'Option 1', value: 1 },
  { label: 'Option 2', value: 2 },
  { label: 'Option 3', value: 3 },
])

const radioVal = ref(1)
</script>

<template>
  <z-radio v-model="radioVal" is-cancel :options="options" />
</template>

Button Style ​

Set type for a certain item in option or pass type directly to the component

<script lang="ts" setup>
import { ref } from 'vue'

const options = ref([
  { label: 'Option 1', value: 1 },
  { label: 'Option 2', value: 2 },
  { label: 'Option 3', value: 3, type: 'radio-button' },
])

const radioVal = ref(1)
</script>

<template>
  <div class="flex flex-col">
    <z-radio v-model="radioVal" type="radio-button" :options="options" />
    <z-radio v-model="radioVal" :options="options" class="mt-4" />
  </div>
</template>

With Border ​

The border attribute or field can be rendered as a radio with border.

<script lang="ts" setup>
import { ref } from 'vue'

const options = ref([
  { label: 'Option 1', value: 1, border: true },
  { label: 'Option 2', value: 2 },
  { label: 'Option 3', value: 3 },
])

const radioVal = ref(1)
</script>

<template>
  <div class="flex flex-col">
    <z-radio v-model="radioVal" :options="options" />
    <z-radio v-model="radioVal" :border="true" :options="options" class="mt-4" />
  </div>
</template>

z-radio Attributes ​

AttributeDescriptionTypeDefault
model-value / v-modelBinding valuestring / number / boolean—
optionsConfigurable optionsarray—
typeRadio formstringradio
aliasKey-value pair configurationobject{ label: 'label', value: 'value', disabled: 'disabled' }
isCancelWhether to cancel selectionbooleanfalse
borderWhether to show borderbooleanfalse
sizeSize of radio button or border buttonstringdefault
disabledWhether to disablebooleanfalse
text-colorText color when radio button is activestring#ffffff
fillFill color and border color when radio button is activestring#409EFF
validate-eventWhether to trigger form validation when inputbooleantrue
nameNative name attributestring—
idNative id attributestring—

z-radio Events ​

Event NameDescriptionType
changeEvent triggered when binding value changesFunction

Options Item Configurable Attributes ​

AttributeDescriptionTypeDefault
valueBinding value of radiostring / number / boolean—
labelText of radiostring—
disabledWhether to disable radiobooleanfalse
borderWhether to show borderbooleanfalse
sizeSize of radioenum—
nameNative name attributestring—
typeRadio formstringel-radio

Released under the MIT License.