Checkbox复选框
选择一个或多个选项,支持选中与不确定状态。
npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add checkbox安装
在项目根目录运行,安装源码。
npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add checkbox使用
React
"use client";
import { useState } from "react";import { KalosCheckbox } from "@/components/ui/kalos-checkbox";
export default function Example() { const [accepted, setAccepted] = useState(false);
return ( <KalosCheckbox label="同意接收产品更新" checked={accepted} onCheckedChange={value => setAccepted(value === true)} /> );}API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
label | string | — | 控件的可见标签 |
description | string | — | 仅在需要补充信息时显示 |
error | string | — | 校验错误;显示时替代说明并关联控件 |
checked | boolean | — | 受控选中状态 |
defaultChecked | boolean | false | 初始状态 |
onCheckedChange | (checked: boolean) => void | — | 选中状态变化时调用 |
indeterminate | boolean | false | 部分选中状态 |
disabled | boolean | false | 禁用复选框 |
键盘操作
- Space
- 切换选中状态
- Tab
- 移动到下一项