111k

Input Group

为输入框添加附加内容、按钮和辅助内容。

12 results
import {
  InputGroup,
  InputGroupAddon,

安装

pnpm dlx shadcn@latest add input-group

用法

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

对齐

使用 InputGroupAddon 上的 align 属性可以相对于输入框定位附加内容。

inline-start

使用 align="inline-start" 可将附加内容定位在输入框起始侧。这是默认值。

Icon positioned at the start.

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

inline-end

使用 align="inline-end" 可将附加内容定位在输入框末尾。

Icon positioned at the end.

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

block-start

使用 align="block-start" 可将附加内容定位在输入框上方。

Full Name

Header positioned above the input.

script.js

Header positioned above the textarea.

import {
  Field,
  FieldDescription,

block-end

使用 align="block-end" 可将附加内容定位在输入框下方。

USD

Footer positioned below the input.

0/280

Footer positioned below the textarea.

import {
  Field,
  FieldDescription,

示例

图标

import {
  InputGroup,
  InputGroupAddon,

文本

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

按钮

https://
"use client"

import * as React from "react"

Kbd

⌘K
import {
  InputGroup,
  InputGroupAddon,

下拉菜单

"use client"

import {

加载指示器

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

文本域

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

自定义输入

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

下面是一个来自第三方库的可调整大小文本域示例。

"use client"

import {

RTL

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

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

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

"use client"

import * as React from "react"

API 参考

InputGroup

用于包裹输入框和附加内容的主组件。

PropTypeDefault
classNamestring
<InputGroup>
  <InputGroupInput />
  <InputGroupAddon />
</InputGroup>

InputGroupAddon

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

PropTypeDefault
align"inline-start" | "inline-end" | "block-start" | "block-end""inline-start"
classNamestring
<InputGroupAddon align="inline-end">
  <SearchIcon />
</InputGroupAddon>

For <InputGroupInput />, use the inline-start or inline-end alignment. For <InputGroupTextarea />, use the block-start or block-end alignment.

The InputGroupAddon component can have multiple InputGroupButton components and icons.

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

InputGroupButton

在输入组中显示按钮。

PropTypeDefault
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

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.

PropTypeDefault
classNamestring

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

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

InputGroupTextarea

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.

PropTypeDefault
classNamestring

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>