Skip to content
On this page

Radio

Single selection in a set of alternatives

Basic usage

Radio boxes should not have too many options, and if you have a lot of options you should use select boxes instead of radio boxes.

to use the Radio component, you only need to set the 'v-model' binding variable, checked means that the value of the variable is the corresponding Radio The value of the value attribute, 'value' can be String, Number or Boolean.

<>
<template>
    <kl-radio-group v-model="value">
        <kl-radio label="HuTao" value="胡桃"></kl-radio>
        <kl-radio label="YeLan" value="夜兰"></kl-radio>
        <kl-radio label="QiQi" value="七七"></kl-radio>
    </kl-radio-group>
</template>

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

const value = ref('')
</script>

Radio is used alone

Radio can also be used alone, and the same data needs to be bound to all radios.

<>
<template>
    <kl-radio label="HuTao" value="胡桃" v-model="value"></kl-radio>
    <kl-radio label="YeLan" value="夜兰" v-model="value"></kl-radio>
    <kl-radio label="QiQi" value="七七" v-model="value"></kl-radio>
</template>

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

const value = ref('')
</script>

Disabled state

The 'disabled' property can be used to control the disabled state of the radio box.

You only need to set the 'disabled' attribute for radio-group to control all option disabled states.

<>
<template>
    <kl-radio-group v-model="value" disabled>
        <kl-radio label="HuTao" value="胡桃"></kl-radio>
        <kl-radio label="YeLan" value="夜兰"></kl-radio>
        <kl-radio label="QiQi" value="七七"></kl-radio>
    </kl-radio-group>
</template>

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

const value = ref('')
</script>

Disable option

Setting the 'disabled' attribute for radio disables the option.

<>
<template>
    <kl-radio-group v-model="value">
        <kl-radio label="HuTao" value="胡桃" disabled></kl-radio>
        <kl-radio label="YeLan" value="夜兰"></kl-radio>
        <kl-radio label="QiQi" value="七七"></kl-radio>
    </kl-radio-group>
</template>

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

const value = ref('')
</script>

With a border

Set the border property to true to render as a radio box with a border.

<>
<template>
    <kl-radio-group v-model="value" border>
        <kl-radio label="HuTao" value="胡桃" disabled></kl-radio>
        <kl-radio label="YeLan" value="夜兰"></kl-radio>
        <kl-radio label="QiQi" value="七七"></kl-radio>
    </kl-radio-group>
</template>

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

const value = ref('')
</script>

icon

Icons can be passed in within a slot

<>
<template>
    <kl-radio-group v-model="value">
        <kl-radio value="Basketball"><KlSportBasketball /></kl-radio>
        <kl-radio value="Football"><KlSportFootball /></kl-radio>
        <kl-radio value="Tennis"><KlSportTennis /></kl-radio>
    </kl-radio-group>
</template>

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

const value = ref('')
</script>

API

Radio attribute

Property nameDescriptionTypeDefault value
v-modelBinding valueboolean
valueThe value of the optionstring / number / boolean / object
labelThe label of the option, if not set, defaults to the same as valuestring/number
disabledWhether to disable the optionbooleanfalse
borderWhether to display a borderbooleanfalse

Radio slot

Slot nameDescription
defaultDefault slot

RadioGroup attribute

Property nameDescriptionTypeDefault value
v-modelBinding valueboolean
disabledWhether to disable all optionsbooleanfalse
borderWhether to display all option bordersbooleanfalse

RadioGroup event

Event NameDescriptionCallback parameters
changeTriggers only when modelValue changes

Released under the MIT License.