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><BfRadiolabel="选项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><BfRadioGroupvalue={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><BfRadioGroupvalue={'1'}groups={[{ label: '选项1', value: '1' },{ label: '选项2', value: '2' },{ label: '选项3', value: '3' },]}layout="vertical"/></>);};
API
属性名 | 描述 | 类型 | 默认值 |
---|---|---|---|
selectable | 是否开启选择模式。开启后点击 label 会触发 onLabelClick,点击 icon 才会触发 onChange | boolean | false |
label | 单选框 label | any | -- |
value | 单选框 value | any | (必选) |
checked | 是否选中 | boolean | false |
selected | 是否 label 文字高亮 | boolean | false |
disable | 是否禁用 @deprecated - use disabled instead | boolean | -- |
disabled | 是否禁用 | boolean | false |
iconClass | icon 类名 | string | -- |
onChange | 选中态变更回调 | (previousVal: any, props: IBfRadioProps & ViewProps) => void | -- |
onLabelClick | 点击 label 的回调 | (props: IBfRadioProps & ViewProps) => void | -- |