Elements

组件

开关 Switch

Switch:开关。关闭时轨道呈纸面的内凹阴影,开启后用 primary 墨色平铺填充,手柄以回弹曲线滑动。部件:Root、Label、Control、Thumb、HiddenInput。

#基础用法

switch/basic Vue React

#属性

#Control

纯造型的部件——自身没有属性,沿用部件结构的共享样式。

#HiddenInput

纯造型的部件——自身没有属性,沿用部件结构的共享样式。

#Label

纯造型的部件——自身没有属性,沿用部件结构的共享样式。

#Root

属性类型默认值描述
sizeString as PropType<"sm" | "md" | "lg">"md"开关手柄的尺寸档位,轨道随之变化
checkedbooleanswitch 的受控选中状态
defaultCheckedbooleanswitch 渲染时的初始选中状态;不需要控制选中状态时使用
disabledbooleanswitch 是否禁用
formstringswitch 所属表单的 id
idstring组件内部状态机的唯一标识
idsPartial<{ root: string; hiddenInput: string; control: string; label: string; thumb: string; }>switch 各元素的 id,适合组合使用
invalidboolean为 true 时 switch 标记为无效
labelstring无障碍元素及其状态的本地化文案
namestringswitch 中 input 字段的 name,用于表单提交
readOnlybooleanswitch 是否只读
requiredboolean为 true 时 switch input 标记为必填
valuestring"on"复选框 input 的值,用于表单提交

#Thumb

纯造型的部件——自身没有属性,沿用部件结构的共享样式。