🌐 Nodejs.cn

输入组

向输入添加插件、按钮和辅助内容。

12 results
import {
  InputGroup,
  InputGroupAddon,

安装

🌐 Installation

pnpm dlx shadcn@latest add input-group

用法

🌐 Usage

import {
  InputGroup,
  InputGroupAddon,
  InputGroupButton,
  InputGroupInput,
  InputGroupText,
  InputGroupTextarea,
} from "@/components/ui/input-group"
<InputGroup>
  <InputGroupInput placeholder="Search..." />
  <InputGroupAddon>
    <SearchIcon />
  </InputGroupAddon>
</InputGroup>

对齐

🌐 Align

InputGroupAddon 上使用 align 属性将附加组件相对于输入框定位。

🌐 Use the align prop on InputGroupAddon to position the addon relative to the input.

inline-start

使用 align="inline-start" 将插件定位在输入的开头。这是默认设置。

🌐 Use align="inline-start" to position the addon at the start of the input. This is the default.

Icon positioned at the start.

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import {
  InputGroup,

inline-end

使用 align="inline-end" 将插件定位在输入的末尾。

🌐 Use align="inline-end" to position the addon at the end of the input.

Icon positioned at the end.

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import {
  InputGroup,

block-start

使用 align="block-start" 将插件定位在输入框上方。

🌐 Use align="block-start" to position the addon above the input.

Full Name

Header positioned above the input.

script.js

Header positioned above the textarea.

import {
  Field,
  FieldDescription,

block-end

使用 align="block-end" 将插件放置在输入框下方。

🌐 Use align="block-end" to position the addon below the input.

USD

Footer positioned below the input.

0/280

Footer positioned below the textarea.

import {
  Field,
  FieldDescription,

示例

🌐 Examples

图标

🌐 Icon

import {
  InputGroup,
  InputGroupAddon,

文本

🌐 Text

$
USD
https://
.com
@company.com
120 characters left
import {
  InputGroup,
  InputGroupAddon,

按钮

🌐 Button

https://
"use client"

import * as React from "react"

键盘

🌐 Kbd

⌘K
import {
  InputGroup,
  InputGroupAddon,

🌐 Dropdown

import {
  DropdownMenu,
  DropdownMenuContent,

旋转器

🌐 Spinner

Saving...
Please wait...
import {
  InputGroup,
  InputGroupAddon,

文本区域

🌐 Textarea

Line 1, Column 1
script.js
import {
  InputGroup,
  InputGroupAddon,

自定义输入

🌐 Custom Input

data-slot="input-group-control" 属性添加到你的自定义输入中,以自动处理焦点状态。

🌐 Add the data-slot="input-group-control" attribute to your custom input for automatic focus state handling.

这是一个来自第三方库的可自定义可调整大小的文本区域示例。

🌐 Here's an example of a custom resizable textarea from a third-party library.

"use client"

import {

从右到左

🌐 RTL

要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南

🌐 To enable RTL support in shadcn/ui, see the RTL configuration guide.

١٢ نتيجة
جاري الحفظ...
٠/٢٨٠

تذييل موضع أسفل منطقة النص.

"use client"

import * as React from "react"

API参考

🌐 API Reference

InputGroup

封装输入和附加组件的主要组件。

🌐 The main component that wraps inputs and addons.

属性类型默认值
classNamestring
<InputGroup>
  <InputGroupInput />
  <InputGroupAddon />
</InputGroup>

InputGroupAddon

在输入项旁显示图标、文本、按钮或其他内容。

🌐 Displays icons, text, buttons, or other content alongside inputs.

属性类型默认值
align"inline-start" | "inline-end" | "block-start" | "block-end""inline-start"
classNamestring
<InputGroupAddon align="inline-end">
  <SearchIcon />
</InputGroupAddon>

对于 <InputGroupInput />,使用 inline-startinline-end 对齐方式。对于 <InputGroupTextarea />,使用 block-startblock-end 对齐方式。

InputGroupAddon 组件可以包含多个 InputGroupButton 组件和图标。

🌐 The InputGroupAddon component can have multiple InputGroupButton components and icons.

<InputGroupAddon>
  <InputGroupButton>Button</InputGroupButton>
  <InputGroupButton>Button</InputGroupButton>
</InputGroupAddon>

InputGroupButton

在输入组中显示按钮。

🌐 Displays buttons within input groups.

属性类型默认值
size"xs" | "icon-xs" | "sm" | "icon-sm""xs"
variant"default" | "destructive" | "outline" | "secondary" | "ghost" | "link""ghost"
classNamestring
<InputGroupButton>Button</InputGroupButton>
<InputGroupButton size="icon-xs" aria-label="Copy">
  <CopyIcon />
</InputGroupButton>

InputGroupInput

在构建输入组时替代 <Input />。该组件预先应用了输入组样式,并使用统一的 data-slot="input-group-control" 来处理焦点状态。

🌐 Replacement for <Input /> when building input groups. This component has the input group styles pre-applied and uses the unified data-slot="input-group-control" for focus state handling.

属性类型默认值
classNamestring

所有其他属性都传递给底层的 <Input /> 组件。

🌐 All other props are passed through to the underlying <Input /> component.

<InputGroup>
  <InputGroupInput placeholder="Enter text..." />
  <InputGroupAddon>
    <SearchIcon />
  </InputGroupAddon>
</InputGroup>

InputGroupTextarea

在构建输入组时用于替换 <Textarea />。该组件预先应用了多行文本框组的样式,并使用统一的 data-slot="input-group-control" 来处理聚焦状态。

🌐 Replacement for <Textarea /> when building input groups. This component has the textarea group styles pre-applied and uses the unified data-slot="input-group-control" for focus state handling.

属性类型默认值
classNamestring

所有其他属性都传递给底层的 <Textarea /> 组件。

🌐 All other props are passed through to the underlying <Textarea /> component.

<InputGroup>
  <InputGroupTextarea placeholder="Enter message..." />
  <InputGroupAddon align="block-end">
    <InputGroupButton>Send</InputGroupButton>
  </InputGroupAddon>
</InputGroup>

更新日志

🌐 Changelog

2025-10-06 InputGroup

min-w-0 类添加到 InputGroup 组件。请参见 diff

🌐 Add the min-w-0 class to the InputGroup component. See diff.