组件
开关
切换一项会立即生效的设置。
用法
基础
HTML
<bs:bsui-switch label="Email notifications" defaultChecked="true" />偏好设置
开关会立即生效,因此列表中无需添加保存按钮。
HTML
<bs:bsui-stack direction="column" gap="4">
<bs:bsui-switch name="deploys" label="Deploy summaries" defaultChecked="true" />
<bs:bsui-switch name="failures" label="Build failures" defaultChecked="true" />
<bs:bsui-switch name="news" label="Product news" />
</bs:bsui-stack>只读和禁用
只读开关会显示当前值但不允许切换;禁用开关还会变暗。
HTML
<bs:bsui-stack direction="column" gap="4">
<bs:bsui-switch label="Two factor authentication" defaultChecked="true" readOnly="true" />
<bs:bsui-switch label="Single sign-on" disabled="true" />
</bs:bsui-stack>自定义值
开启和关闭状态可以提交任意内容,不限于 on 和空值。
Submits weekly while it is on and never while it is off.
HTML
<bs:bsui-field>
<bs:bsui-field-label text="Digest emails" />
<bs:bsui-switch name="digest" label="Send a weekly digest" checkedValue="weekly" uncheckedValue="never" defaultChecked="true" />
<bs:bsui-field-description text="Submits weekly while it is on and never while it is off." />
</bs:bsui-field>结构
开关由以下区块组成。每个区块都是独立的区块,只会在其父级内部渲染。
bsui/switchbsui/switch-thumb
属性
| 属性 | 类型 | 默认 |
|---|---|---|
defaultChecked | toggle | false |
disabled | toggle | false |
readOnly | toggle | false |
required | toggle | false |
name | text | — |
checkedValue | text | on |
uncheckedValue | text | — |
label | richtext | — |
bindText | text | — |
nameAlt | text | — |
onChange | text | — |
checked | text | — |
bsui/switch-thumb
此区块不接受任何属性。