Skip to content

Radio Component

The radio component is generally used for scenarios that require multiple selections. This component is fully featured and easy to use

📌Platform Differences

APP(vue)H5WeChat Mini ProgramAlipay Mini Program

🏯Basic Usage Example

html
<!-- Global usage -->
<hy-radio v-model="value" :columns="columns"></hy-radio>
ts
import { ref } from 'vue';

const columns = [
    {
        label: 'Apple',
        value: 'apply',
    },
    {
        label: 'Banana',
        value: 'banana',
    },
];
const value = ref('apply');

Custom columns Keys

html
<hy-radio v-model="value" :columns="columns" :fieldNames="fieldNames"></hy-radio>
ts
import { HyCheckobox } from 'hy-app';
import { ref } from 'vue';

const columns = [
    {
        name: 'Apple',
        value_1: 'apply',
    },
    {
        name: 'Banana',
        value_1: 'banana',
    },
];
const value = ref('');
const fieldNames = ref({
    label: 'name',
    value: 'value_1',
    checked: 'checked',
});

Custom Shape

You can set the checkbox to a square or circle shape by setting shape to square or circle

html
<hy-radio v-model="value" :columns="columns" shape="square"></hy-radio>
<hy-radio v-model="value" :columns="columns" shape="circle"></hy-radio>

Custom Color

html
<hy-radio v-model="value" :columns="columns" activeColor="red"></hy-radio>

Arrangement

You can arrange the checkboxes horizontally or vertically by setting placement to row or column

html
<hy-radio v-model="value" :columns="columns" placement="row"></hy-radio>
<hy-radio v-model="value" :columns="columns" placement="column"></hy-radio>

Horizontal Justified Layout

You can set the alignment of the checkbox selection icon to left-aligned or right-aligned by setting iconPlacement to left or right

html
<hy-radio v-model="value" :columns="columns" iconPlacement="right" placement="row"></hy-radio>
<hy-radio v-model="value" :columns="columns" iconPlacement="left" placement="row"></hy-radio>

Disable

html
<!-- Disable all -->
<hy-radio v-model="value" :columns="columns" disabled></hy-radio>
ts
import { ref } from 'vue';

const columns = [
    {
        label: 'Apple',
        value: 'apply',
        disabled: true, // Disable a single item
    },
    {
        label: 'Banana',
        value: 'banana',
    },
];
const value = ref('apply');

Slots

  • label: Custom label text, the passed value is label
  • icon: Custom icon inside the option box, the passed values are iconColor and iconSize
html
<hy-radio v-model="value" :columns="columns">
    <template #label="{ label }">
        <view>{{label}}</view>
    </template>
    <template #icon="{ iconColor, iconSize }">
        <view>{{iconColor}}</view>
        <view>{{iconSize}}</view>
    </template>
</hy-radio>
ts
import { ref } from 'vue';

const columns = [
    {
        label: 'Apple',
        value: 'apply',
    },
    {
        label: 'Banana',
        value: 'banana',
    },
];
const value = ref('apply');

API

Radio Props

ParameterDescriptionTypeDefault Value
v-modelTwo-way bound value, array typestring|number-
columnsReceives an array valueCheckboxColumnsVo[]-
fieldNamesCustom keys for receiving columnsIFieldNames{label: "label",value: "value",checked: "checked"}
shapeCheckbox shape[1]circle|squarecircle
sizeCheckbox size[2]string|numbermedium
disabledWhether disabledbooleanfalse
activeColorColor in selected statestring-
inactiveColorColor when unselectedstring#c8c9cc
iconSizeIcon size, default unit is px for numeric valuesstring|number20
iconColorIcon colorstring-
labelLabel hint textstring-
labelSizeLabel font size, in pxstring|number-
labelColorLabel colorstring-
iconPlacementAlignment of the check iconleft|rightleft
borderBottomWhether to show the bottom line in vertical arrangementbooleanfalse
labelDisabledWhether to disable selecting the checkbox by clicking the label textbooleanfalse
placementLayout mode[3]row|columnrow
customStyleDefine external styles to be usedCSSProperties-

Events

Event NameDescriptionCallback Parameters
changeTriggered when any radio's state changes, the callback is an objectdetail = array( [elements are the values of the selected radios] )

Slots

Slot NameDescriptionPassed Values
iconCustom icon contenticonColor | iconSize
labelCustom label contentrecord

typing

Type Description
ts
interface CheckboxColumnsVo extends FieldNamesType {
    /**
     * Displayed text content
     * */
    label?: string;
    /**
     * Value
     * */
    value?: string | number;
    /**
     * Whether selected
     * */
    checked?: boolean;

    /**
     * Whether disabled
     * */
    disabled?: boolean;
}

export interface IFieldNames {
    /**
     * Custom text key of columns
     * */
    label: string;
    /**
     * Custom value key of columns
     * */
    value: string;
    /**
     * Custom checked key of columns
     * */
    checked: string;
}
03:29

  1. circle: semicircular on both sides; square: square with rounded corners ↩︎

  2. normal: default size; large: large size; small: small size; ↩︎

  3. row: horizontal; column: vertical ↩︎