RadioButtonGroup
Examples
Size variants
Available ui prop values: s / m.
Normal size
Selected: -
Small size & Square shape
<template>
<article>
<section>
<h4>Normal size</h4>
<veui-radio-button-group
v-model="flavor"
:items="flavors"
/>
<p>Selected: {{ readable }}</p>
</section>
<section>
<h4>Small size &amp; Square shape</h4>
<veui-radio-button-group
ui="s"
:items="actions"
>
<template #item="{ value }">
<veui-icon :name="value"/>
</template>
</veui-radio-button-group>
</section>
</article>
</template>
<script>
import { RadioButtonGroup, Icon } from 'veui'
import 'veui-theme-dls-icons/clockwise'
import 'veui-theme-dls-icons/search'
export default {
components: {
'veui-radio-button-group': RadioButtonGroup,
'veui-icon': Icon
},
data () {
return {
flavor: null,
flavors: [
{ value: 'LATTE', label: 'Latte' },
{ value: 'MOCHA', label: 'Mocha' },
{ value: 'AMERICANO', label: 'Americano' }
],
actions: [
{
label: '刷新',
value: 'clockwise'
},
{
label: '搜索',
value: 'search'
}
]
}
},
computed: {
flavorLabelMap () {
return this.flavors.reduce((map, { value, label }) => {
map[value] = label
return map
}, {})
},
readable () {
return this.flavorLabelMap[this.flavor] || '-'
}
}
}
</script>
<style lang="less" scoped>
section {
margin-bottom: 20px;
}
h4 {
margin-top: 0;
}
</style>
Simple style
Set ui prop value to simple to apply the style variant.
Selected: -
<template>
<article>
<section>
<veui-radio-button-group
v-model="flavor"
ui="simple"
:items="flavors"
/>
<p>Selected: {{ readable }}</p>
</section>
</article>
</template>
<script>
import { RadioButtonGroup } from 'veui'
export default {
components: {
'veui-radio-button-group': RadioButtonGroup
},
data () {
return {
flavor: null,
flavors: [
{ value: 'LATTE', label: 'Latte' },
{ value: 'MOCHA', label: 'Mocha' },
{ value: 'AMERICANO', label: 'Americano' }
]
}
},
computed: {
flavorLabelMap () {
return this.flavors.reduce((map, { value, label }) => {
map[value] = label
return map
}, {})
},
readable () {
return this.flavorLabelMap[this.flavor] || '-'
}
}
}
</script>
<style lang="less" scoped>
section {
margin-bottom: 20px;
}
h4 {
margin-top: 0;
}
</style>
Additional description
Set the desc field in the data source or use the desc slot to specify additional description. The additional description will be displayed on hover.
desc field
desc slot
<template>
<article>
<section>
<h4><code>desc</code> field</h4>
<veui-radio-button-group
v-model="flavor"
:items="flavors"
/>
</section>
<section>
<h4><code>desc</code> slot</h4>
<veui-radio-button-group
v-model="flavor"
:items="flavors"
>
<template #desc="{ desc, label }">
{{ desc || `A description for ${label}` }}
</template>
</veui-radio-button-group>
</section>
</article>
</template>
<script>
import { RadioButtonGroup } from 'veui'
export default {
components: {
'veui-radio-button-group': RadioButtonGroup
},
data () {
return {
flavor: null,
flavors: [
{ value: 'LATTE', label: 'Latte', desc: 'A description for latte.' },
{ value: 'MOCHA', label: 'Mocha', desc: 'A description for mocha.' },
{ value: 'AMERICANO', label: 'Americano' }
]
}
}
}
</script>
<style lang="less" scoped>
section {
margin-bottom: 20px;
}
h4 {
margin-top: 0;
}
</style>
Minimum width
Set ui prop value to stable to enable minimum width for options, making the layout more stable in multi-line scenarios.
<template>
<article>
<section>
<veui-checkbox v-model="isStable">
Stable layout
</veui-checkbox>
</section>
<veui-radio-button-group
v-model="flavor"
:items="flavors"
:ui="isStable ? 'stable' : ''"
/>
</article>
</template>
<script>
import { RadioButtonGroup, Checkbox } from 'veui'
export default {
components: {
'veui-radio-button-group': RadioButtonGroup,
'veui-checkbox': Checkbox
},
data () {
return {
isStable: true,
flavor: null,
flavors: [
{ value: 'LATTE', label: 'Latte' },
{ value: 'MOCHA', label: 'Mocha' },
{ value: 'AMERICANO', label: 'Americano' }
]
}
}
}
</script>
<style lang="less" scoped>
section {
margin-bottom: 20px;
}
h4 {
margin-top: 0;
}
</style>
API
Props
| Name | Type | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ui | string | - | Predefined styles.
| |||||||||||||||
items | Array<Object> | [] | Data source of radio buttons. The type of each item is
| |||||||||||||||
value | * | - |
The list of | |||||||||||||||
disabled | boolean | false | Whether the component is disabled. | |||||||||||||||
readonly | boolean | false | Whether the component is read-only. |
Slots
| Name | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
item | Text area inside the button. Default content:
In addition, properties other than those described above in the | ||||||||||||||||||
desc | Additional description information for the button. Slot parameters are the same as those of the item slot. |
Events
| Name | Description |
|---|---|
change |
Triggered after the selection status changes. The callback parameter is |
CSS
| Name | Type | Default | Description |
|---|---|---|---|
--dls-checkbox-button-min-width | <length> | - | Minimum width of options when ui is set to stable. |