Skip to content

Radio Component ​

The radio component is generally used in scenarios where a selection among multiple options is required. It is fully functional and easy to use.

📌 Platform Differences ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

🏯 Basic Usage ​

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 shape to square or circle to render the selection box as a square or a 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>

Layout Direction ​

You can set placement to row or column to arrange the radios horizontally or vertically

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

Horizontal Layout with Icon Positioning ​

You can set iconPlacement to left or right to align the check icon to the left or to the 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>

Disabled ​

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 selection 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
v-modelTwo-way bound valuestring|number-
columnsAccepts an array of optionsCheckboxColumnsVo[]-
fieldNamesCustom keys for the columns fieldsIFieldNames{label: "label",value: "value",checked: "checked"}
shapeShape of the selection box[1]circle|squarecircle
sizeSize of the selection box[2]string|numbermedium
disabledWhether to disablebooleanfalse
activeColorColor in the selected statestring-
inactiveColorColor in the unselected statestring#c8c9cc
iconSizeIcon size; numeric values default to pxstring|number20
iconColorIcon colorstring-
labelLabel hint textstring-
labelSizeLabel font size, in pxstring|number-
labelColorLabel colorstring-
iconPlacementAlignment of the check iconleft|rightleft
borderBottomWhether to show an underline when arranged verticallybooleanfalse
labelDisabledWhether clicking the label text to select the radio is disabledbooleanfalse
placementLayout[3]row|columnrow
customStyleExternal styles to applyCSSProperties-

Events ​

EventDescriptionCallback Parameters
changeTriggered when the state of any radio changes; the callback is an objectdetail = array( [each element is the value of a selected radio] )

Slots ​

SlotDescriptionPassed Value
iconCustom icon contenticonColor | iconSize
labelCustom label contentrecord

typing ​

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

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

export interface IFieldNames {
    /**
     * Custom label key for columns
     * */
    label: string;
    /**
     * Custom value key for columns
     * */
    value: string;
    /**
     * Custom checked key for columns
     * */
    checked: string;
}

CSS Variables ​

VariableDescriptionDefault
--hy-radio-marginOuter margin5px
--hy-radio-radius-squareBorder radius of the square dot frame3px
--hy-radio-disabled-checked-opacityOpacity when disabled and checked0.5
--hy-radio-label-colorLabel text colorFollows --hy-text-color
--hy-radio-font-sizeLabel font sizeFollows --hy-font-size-base (28rpx)
--hy-radio-disabled-colorDisabled text colorFollows --hy-text-color--disabled
--hy-radio-borderDot frame borderFollows --hy-border-line
12:33
battery

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

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

  3. row: horizontal; column: vertical ↩︎