表单与选择@neumorphism-ui/input-group

Input Group

可在 InputGroupInput 或 InputGroupTextarea 前后组合 addon、辅助文本和 button。根元素的 focus-within 状态为整个组合提供统一的焦点表现。

@neumorphism-ui/input-group
Registry JSON

预览

https://

安装

安装: input-groupnpx shadcn@latest add @neumorphism-ui/input-group

CLI 会依次处理 npm 依赖、base token、utils 和组件源码。

首次使用此 Registry?请先完成 namespace 配置 。

用法

用法: 安装npx shadcn@latest add @neumorphism-ui/input-group @neumorphism-ui/label

Import

Input Group import 代码
import {
  InputGroup,
  InputGroupAddon,
  InputGroupButton,
  InputGroupInput,
  InputGroupText,
} from "@/components/ui/input-group"
import { Label } from "@/components/ui/label"

Example

Input Group 用法代码
<div className="grid gap-2">
  <Label htmlFor="workspace">工作区</Label>
  <InputGroup>
    <InputGroupAddon aria-hidden="true"><svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><circle cx="11" cy="11" r="7" /><path d="m20 20-4-4" /></svg></InputGroupAddon>
    <InputGroupInput id="workspace" defaultValue="soft-interface" />
    <InputGroupButton type="button">搜索</InputGroupButton>
  </InputGroup>
</div>

API 参考

组件属性类型默认值说明
InputGroupchildren必填React.ReactNode—按顺序排列 control、addon、text 和 button。
InputGrouparia-label / aria-labelledbystring—在需要时为 role=group 提供整个组合的名称。
InputGroupInputnative input propsReact.ComponentProps<"input">—id、name、type、value、onChange 等原生属性。
InputGroupTextareanative textarea propsReact.ComponentProps<"textarea">—多行 control 的原生属性。
InputGroupButtontype"button" | "submit" | "reset""button"设置组合内操作按钮的类型。

无障碍

  • 01

    根元素的 role=group 不会为 input 命名,因此仍需将 control 本身与 Label 关联。

  • 02

    纯装饰 addon 应设置 aria-hidden=true;单位、前缀等必要文本则应保留朗读。

  • 03

    仅含图标的 InputGroupButton 必须提供 aria-label。