Radio

Radio 单选框

代码示例

import { BfRadio, BfRadioGroup } from '@bud-fe/react-taro-ui';
import { View } from '@tarojs/components';
import React, { useState } from 'react';
export default () => {
const [singleChecked, setSingleChecked] = useState(true);
const [groupChecked, setGroupChecked] = useState('1');
return (
<>
<View className="group-title">BfRadio - 基本用法</View>
<BfRadio
label="选项1"
value="1"
checked={singleChecked}
onChange={() => {
setSingleChecked((pre) => !pre);
}}
/>
<View className="group-title">BfRadio - disabled=true</View>
<BfRadio label="选项1" value="1" disabled />
<View className="group-title">BfRadioGroup - 基本用法</View>
<BfRadioGroup
value={groupChecked}
groups={[
{ label: '选项1', value: '1' },
{ label: '选项2', value: '2' },
{ label: '选项3', value: '3' },
{ label: '选项4', value: '4' },
{ label: '选项5', value: '5' },
{ label: '选项6', value: '6' },
{ label: '选项7', value: '7' },
]}
onChange={(val) => setGroupChecked(val)}
/>
<View className="group-title">BfRadioGroup - 垂直布局</View>
<BfRadioGroup
value={'1'}
groups={[
{ label: '选项1', value: '1' },
{ label: '选项2', value: '2' },
{ label: '选项3', value: '3' },
]}
layout="vertical"
/>
</>
);
};

API

属性名描述类型默认值
selectable是否开启选择模式。开启后点击 label 会触发 onLabelClick,点击 icon 才会触发 onChangebooleanfalse
label单选框 labelany--
value单选框 valueany(必选)
checked是否选中booleanfalse
selected是否 label 文字高亮booleanfalse
disable是否禁用 @deprecated - use disabled insteadboolean--
disabled是否禁用booleanfalse
iconClassicon 类名string--
onChange选中态变更回调(previousVal: any, props: IBfRadioProps & ViewProps) => void--
onLabelClick点击 label 的回调(props: IBfRadioProps & ViewProps) => void--
dumi10:24