组件
- 手风琴 (Accordion)
- 警示框 (Alert)
- 对话框 (Alert Dialog)
- 宽高比 (Aspect Ratio)
- 头像 (Avatar)
- 徽章 (Badge)
- 面包屑 (Breadcrumb)
- 按钮 (Button)
- 按钮组 (Button Group)
- 日历 (Calendar)
- 卡片 (Card)
- 轮播 (Carousel)
- 图表 (Chart)
- 复选框 (Checkbox)
- 折叠面板 (Collapsible)
- 组合框 (Combobox)
- 命令栏 (Command)
- 上下文菜单 (Context Menu)
- 数据表格 (Data Table)
- 日期选择器 (Date Picker)
- 对话框 (Dialog)
- 方向 (Direction)
- 抽屉 (Drawer)
- 下拉菜单 (Dropdown Menu)
- 空状态 (Empty)
- 字段 (Field)
- 悬浮卡片 (Hover Card)
- 输入框 (Input)
- 输入框组 (Input Group)
- OTP 输入框 (Input OTP)
- 项目 (Item)
- 快捷键 (Kbd)
- 标签 (Label)
- 菜单栏 (Menubar)
- 原生选择框 (Native Select)
- 导航菜单 (Navigation Menu)
- 分页 (Pagination)
- 气泡卡片 (Popover)
- 进度条 (Progress)
- 单选组 (Radio Group)
- 可调节大小 (Resizable)
- 滚动区域 (Scroll Area)
- 选择框 (Select)
- 分隔线 (Separator)
- 侧边栏 (Sheet)
- 导航侧边栏 (Sidebar)
- 骨架屏 (Skeleton)
- 滑块 (Slider)
- Sonner (吐司通知)
- 加载器 (Spinner)
- 开关 (Switch)
- 表格 (Table)
- 标签页 (Tabs)
- 文本域 (Textarea)
- 吐司 (Toast)
- 切换按钮 (Toggle)
- 切换组 (Toggle Group)
- 文字提示 (Tooltip)
- 排版 (Typography)
您的 API 密钥已加密并安全存储。
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
安装
pnpm dlx shadcn@latest add input
用法
import { Input } from "@/components/ui/input"<Input />示例
基础用法
import { Input } from "@/components/ui/input"
export function InputBasic() {字段 (Field)
使用 Field、FieldLabel 和 FieldDescription 来创建一个带有标签和描述的输入框。
为您的账户选择一个唯一的用户名。
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
字段组 (Field Group)
使用 FieldGroup 来展示多个 Field 块并构建表单。
我们将向此地址发送更新。
import { Button } from "@/components/ui/button"
import {
Field,禁用
使用 disabled 属性来禁用输入框。要设置禁用状态的样式,请为 Field 组件添加 data-disabled 属性。
此字段当前已禁用。
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
无效状态
使用 aria-invalid 属性将输入标记为无效。要设置无效状态的样式,请为 Field 组件添加 data-invalid 属性。
此字段包含验证错误。
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
文件上传
使用 type="file" 属性来创建文件输入框。
选择要上传的图片。
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
内联
将 Field 与 orientation="horizontal" 一起使用以创建内联输入框。配合 Button 使用可创建一个带有按钮的搜索框。
import { Button } from "@/components/ui/button"
import { Field } from "@/components/ui/field"
import { Input } from "@/components/ui/input"网格
使用网格布局来并排放置多个输入框。
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
必填
使用 required 属性来标示必填输入项。
此字段必须填写。
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
徽章
在标签中使用 Badge 来高亮显示推荐字段。
import { Badge } from "@/components/ui/badge"
import { Field, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"输入框组
要在输入框内添加图标、文本或按钮,请使用 InputGroup 组件。更多示例请参见 输入组 (Input Group) 组件。
https://
import { Field, FieldLabel } from "@/components/ui/field"
import {
InputGroup,按钮组
要在输入框中添加按钮,请使用 ButtonGroup 组件。更多示例请参见 按钮组 (Button Group) 组件。
import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"
import { Field, FieldLabel } from "@/components/ui/field"表单
一个包含多个输入框、下拉选择框和按钮的完整表单示例。
import { Button } from "@/components/ui/button"
import {
Field,RTL (从右至左)
要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南。
您的 API 密钥已加密并安全存储。
"use client"
import * as React from "react"