跳转到正文

组件

单选按钮组

一组选项中只能选择一个。

用法

基础

HTML
<bs:bsui-radio-group defaultValue="pro">
  <bs:bsui-radio value="free" label="Free" />
  <bs:bsui-radio value="pro" label="Pro" />
  <bs:bsui-radio value="enterprise" label="Enterprise" />
</bs:bsui-radio-group>

水平

方向设置会将简短的选项列表横向排列。

HTML
<bs:bsui-radio-group name="priority" defaultValue="normal" orientation="horizontal">
  <bs:bsui-radio value="low" label="Low" />
  <bs:bsui-radio value="normal" label="Normal" />
  <bs:bsui-radio value="urgent" label="Urgent" />
</bs:bsui-radio-group>

不可用选项

可以禁用单个选项,同时保持组内其他选项可用。

HTML
<bs:bsui-radio-group name="plan" defaultValue="pro">
  <bs:bsui-radio value="free" label="Free" />
  <bs:bsui-radio value="pro" label="Pro" />
  <bs:bsui-radio value="enterprise" label="Enterprise, contact sales" disabled="true" />
</bs:bsui-radio-group>

位于字段中

标签、帮助文本和错误消息作用于整个组,而不是某个单独选项。

This cannot be changed after the first backup runs. Pick a region to enable backups.
HTML
<bs:bsui-field invalid="true">
  <bs:bsui-field-label text="Where should backups live?" />
  <bs:bsui-radio-group name="backups">
    <bs:bsui-radio value="eu" label="Europe" />
    <bs:bsui-radio value="us" label="United States" />
  </bs:bsui-radio-group>
  <bs:bsui-field-description text="This cannot be changed after the first backup runs." />
  <bs:bsui-field-error text="Pick a region to enable backups." />
</bs:bsui-field>

结构

单选按钮组由以下区块组成。每个区块都是独立的区块,只会在其父级内部渲染。

  • bsui/radio-group
  • bsui/radio

属性

属性类型默认
defaultValue text —
name text —
disabled toggle false
orientation vertical horizontal vertical
nameAlt text —
onChange text —
value text —

bsui/radio

属性类型默认
value text —
label richtext —
disabled toggle false
bindText text —