mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-27 06:34:12 +00:00
* feat: add field.tsx and update blocks * feat: add input group * feat: implement button group * fix * fix * wip * fix: button group * feat: update field * fix * feat * feat: cooked * fix * chore: build registry * feat: add kbd component * chore: update input group demo * feat: update kbd component * feat: add empty * feat: add spinner * refactor: input group * feat: blocks * fix * fix: app sidebar * feat: add label to app sidebar * fix * fix * fix * fix * fix * feat * feat * fix * docs: button group * feat: add docs * docs: kbd * docs: empty * fix * docs * docs * feat: add sink link * fix * fix * docs * feat: add new page * fix * fix * fix * fix * fix * fix * feat: add registration form * fix: chat settings * fix * fix preview * fix examples * feat: add changelog * fix * fix * fix * fix * fix * feat(www): add t3 versions * chore: build registry * fix * fix * fix * feat: inline code examples for llm * fix * feat: home * fix * fix * fix * fix * fix * chore: changelog * fix * fix * fix * fix: callout * fix
256 lines
6.7 KiB
Plaintext
256 lines
6.7 KiB
Plaintext
---
|
|
title: Input Group
|
|
description: Display additional information or actions to an input or textarea.
|
|
component: true
|
|
---
|
|
|
|
import { IconInfoCircle } from "@tabler/icons-react"
|
|
|
|
<ComponentPreview name="input-group-demo" className="[&_.preview]:p-4" />
|
|
|
|
## Installation
|
|
|
|
<CodeTabs>
|
|
|
|
<TabsList>
|
|
<TabsTrigger value="cli">CLI</TabsTrigger>
|
|
<TabsTrigger value="manual">Manual</TabsTrigger>
|
|
</TabsList>
|
|
<TabsContent value="cli">
|
|
|
|
```bash
|
|
npx shadcn@latest add input-group
|
|
```
|
|
|
|
</TabsContent>
|
|
|
|
<TabsContent value="manual">
|
|
|
|
<Steps>
|
|
|
|
<Step>Copy and paste the following code into your project.</Step>
|
|
|
|
<ComponentSource name="input-group" title="components/ui/input-group.tsx" />
|
|
|
|
<Step>Update the import paths to match your project setup.</Step>
|
|
|
|
</Steps>
|
|
|
|
</TabsContent>
|
|
|
|
</CodeTabs>
|
|
|
|
## Usage
|
|
|
|
```tsx showLineNumbers
|
|
import {
|
|
InputGroup,
|
|
InputGroupAddon,
|
|
InputGroupButton,
|
|
InputGroupInput,
|
|
InputGroupText,
|
|
InputGroupTextarea,
|
|
} from "@/components/ui/input-group"
|
|
```
|
|
|
|
```tsx showLineNumbers
|
|
<InputGroup>
|
|
<InputGroupInput placeholder="Search..." />
|
|
<InputGroupAddon>
|
|
<SearchIcon />
|
|
</InputGroupAddon>
|
|
<InputGroupAddon align="inline-end">
|
|
<InputGroupButton>Search</InputGroupButton>
|
|
</InputGroupAddon>
|
|
</InputGroup>
|
|
```
|
|
|
|
## Examples
|
|
|
|
### Icon
|
|
|
|
<ComponentPreview name="input-group-icon" className="[&_.preview]:p-4" />
|
|
|
|
### Text
|
|
|
|
Display additional text information alongside inputs.
|
|
|
|
<ComponentPreview name="input-group-text" className="[&_.preview]:p-4" />
|
|
|
|
### Button
|
|
|
|
Add buttons to perform actions within the input group.
|
|
|
|
<ComponentPreview name="input-group-button" className="[&_.preview]:p-4" />
|
|
|
|
### Tooltip
|
|
|
|
Add tooltips to provide additional context or help.
|
|
|
|
<ComponentPreview name="input-group-tooltip" className="[&_.preview]:p-4" />
|
|
|
|
### Textarea
|
|
|
|
Input groups also work with textarea components. Use `block-start` or `block-end` for alignment.
|
|
|
|
<ComponentPreview name="input-group-textarea" className="[&_.preview]:p-4" />
|
|
|
|
### Spinner
|
|
|
|
Show loading indicators while processing input.
|
|
|
|
<ComponentPreview name="input-group-spinner" className="[&_.preview]:p-4" />
|
|
|
|
### Label
|
|
|
|
Add labels within input groups to improve accessibility.
|
|
|
|
<ComponentPreview name="input-group-label" className="[&_.preview]:p-4" />
|
|
|
|
### Dropdown
|
|
|
|
Pair input groups with dropdown menus for complex interactions.
|
|
|
|
<ComponentPreview name="input-group-dropdown" className="[&_.preview]:p-4" />
|
|
|
|
### Button Group
|
|
|
|
Wrap input groups with button groups to create prefixes and suffixes.
|
|
|
|
<ComponentPreview
|
|
name="input-group-button-group"
|
|
className="[&_.preview]:p-4"
|
|
/>
|
|
|
|
### Custom Input
|
|
|
|
Add the `data-slot="input-group-control"` attribute to your custom input for automatic behavior and focus state handling.
|
|
|
|
No style is applied to the custom input. Apply your own styles using the `className` prop.
|
|
|
|
<ComponentPreview
|
|
name="input-group-custom"
|
|
className="!mb-4 [&_.preview]:p-4"
|
|
/>
|
|
|
|
```tsx showLineNumbers
|
|
import { InputGroup, InputGroupAddon } from "@/component/ui/input-group"
|
|
import TextareaAutosize from "react-textarea-autosize"
|
|
|
|
export function InputGroupCustom() {
|
|
return (
|
|
<InputGroup>
|
|
<TextareaAutosize
|
|
data-slot="input-group-control"
|
|
className="dark:bg-input/30 flex field-sizing-content min-h-16 w-full resize-none rounded-md bg-transparent px-3 py-2 text-base transition-[color,box-shadow] outline-none"
|
|
placeholder="Autoresize textarea..."
|
|
/>
|
|
<InputGroupAddon align="block-end">how</InputGroupAddon>
|
|
</InputGroup>
|
|
)
|
|
}
|
|
```
|
|
|
|
## API Reference
|
|
|
|
### InputGroup
|
|
|
|
The main component that wraps inputs and addons.
|
|
|
|
| Prop | Type | Default |
|
|
| ----------- | -------- | ------- |
|
|
| `className` | `string` | |
|
|
|
|
```tsx
|
|
<InputGroup>
|
|
<InputGroupInput />
|
|
<InputGroupAddon />
|
|
</InputGroup>
|
|
```
|
|
|
|
### InputGroupAddon
|
|
|
|
Displays icons, text, buttons, or other content alongside inputs.
|
|
|
|
<Callout icon={<IconInfoCircle />} title="Focus Navigation">
|
|
For proper focus navigation, the `InputGroupAddon` component should be placed
|
|
after the input. Set the `align` prop to position the addon.
|
|
</Callout>
|
|
|
|
| Prop | Type | Default |
|
|
| ----------- | ---------------------------------------------------------------- | ---------------- |
|
|
| `align` | `"inline-start" \| "inline-end" \| "block-start" \| "block-end"` | `"inline-start"` |
|
|
| `className` | `string` | |
|
|
|
|
```tsx
|
|
<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.
|
|
|
|
```tsx
|
|
<InputGroupAddon>
|
|
<InputGroupButton>Button</InputGroupButton>
|
|
<InputGroupButton>Button</InputGroupButton>
|
|
</InputGroupAddon>
|
|
```
|
|
|
|
### InputGroupButton
|
|
|
|
Displays buttons within input groups.
|
|
|
|
| Prop | Type | Default |
|
|
| ----------- | ----------------------------------------------------------------------------- | --------- |
|
|
| `size` | `"xs" \| "icon-xs" \| "sm" \| "icon-sm"` | `"xs"` |
|
|
| `variant` | `"default" \| "destructive" \| "outline" \| "secondary" \| "ghost" \| "link"` | `"ghost"` |
|
|
| `className` | `string` | |
|
|
|
|
```tsx
|
|
<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.
|
|
|
|
| Prop | Type | Default |
|
|
| ----------- | -------- | ------- |
|
|
| `className` | `string` | |
|
|
|
|
All other props are passed through to the underlying `<Input />` component.
|
|
|
|
```tsx
|
|
<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.
|
|
|
|
| Prop | Type | Default |
|
|
| ----------- | -------- | ------- |
|
|
| `className` | `string` | |
|
|
|
|
All other props are passed through to the underlying `<Textarea />` component.
|
|
|
|
```tsx
|
|
<InputGroup>
|
|
<InputGroupTextarea placeholder="Enter message..." />
|
|
<InputGroupAddon align="block-end">
|
|
<InputGroupButton>Send</InputGroupButton>
|
|
</InputGroupAddon>
|
|
</InputGroup>
|
|
```
|