Label.tsx

Label.tsx

基本信息

  • 类型: React 组件 (shadcn/ui)
  • 路径: ./src/components/ui/label.tsx

功能描述

标签组件,用于表单字段的标签文本。基于 Radix UI,支持禁用状态样式。

导出内容

  • Label - 标签组件

Props 接口

Label

属性类型必填默认值说明
classNamestring-自定义CSS类名
htmlForstring-关联的输入框 ID
...propsReact.ComponentProps<typeof LabelPrimitive.Root>-Radix Label 属性

依赖

  • @radix-ui/react-label - Radix UI 标签原语
  • @/lib/utils - 工具函数 (cn)

使用示例

import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";

// 基础用法
<div className="grid w-full max-w-sm items-center gap-1.5">
  <Label htmlFor="email">邮箱地址</Label>
  <Input type="email" id="email" />
</div>

// 在 Form 中使用
<FormItem>
  <FormLabel>用户名</FormLabel>
  <FormControl>
    <Input {...field} />
  </FormControl>
</FormItem>
← 返回目录