组件

Input Group

One hand-drawn field around an icon, some text, a button and the control, so a search box or a URL field is a single box instead of three. The box takes the control's focus, invalid and disabled states, and grows with a textarea. The same parts as shadcn's Input Group.

安装

terminal
npx shadcn@latest add @wobko/input-group

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Default

One hand-drawn box around an icon, the field and some text. Click anywhere on an addon and the field takes focus; the focus ring goes around the whole group.

Buttons and states

Buttons go inside an addon (ghost, xs by default). The control's own state paints the group: aria-invalid draws the red box, disabled the dashed one, and `data-disabled` on the group disables it as a whole.

Comment box

Block addons stack above or below a textarea inside the same drawn box: a header line on top, a counter and a send button underneath. The box grows with the text and is redrawn to fit.

Subscribe form

A real-world use: a labeled group in a form. The label points at the control, the marker button is part of the same box, and a bad address turns the whole group red.

Four groups

shadcn's `input-group-demo`: a search with a result count, a URL with a prefix and a tooltip button, a prompt box with a menu and a send button, and a field with a verified badge. The badge is a drawn `badge-check` where the original has a filled circle.

Labels

shadcn's `input-group-label`: a Label can be an addon, so the @ in front of a handle is a real label for the field, or a title above it (`block-start`) with a help button at the far end.

Text addons

shadcn's `input-group-text`: `InputGroupText` sets plain words beside the field (a currency sign, a scheme, a domain) or under a textarea as a counter. The text is part of the box, not the value.

Tooltips

shadcn's `input-group-tooltip`: help buttons that explain themselves. Two sit at the end as ghost icon buttons; in the third the note opens to the left (`side="left"`), on the leading addon. The original makes the addon itself the trigger; here the button inside it is, so the tooltip is tied to the control that has focus.

Buttons

shadcn's `input-group-button`: a copy button that turns into a tick, a popover from the button in the leading addon (the button is the trigger, so it is the thing that says it is expanded), a star that toggles, and a text button that ends the box. The original's `useCopyToClipboard` hook is a few lines of state here.

Inside a button group

shadcn's `input-group-button-group`: an InputGroup as the middle of a ButtonGroup, with `https://` and `.com` as text cells on either side. The first cell is a Label (`asChild`), so it focuses the field.

Dropdowns

shadcn's `input-group-dropdown`: a menu opened from a button inside the box, once as an ellipsis icon and once as a labeled `Search In...` with a chevron. The menu drops from the button; the box stays put.

Spinners

shadcn's `input-group-spinner`: `data-disabled` on the group dims the whole box while something is working, with a Spinner or a spinning icon in either addon and a word or two of status.

Textarea with header and footer

shadcn's `input-group-textarea`: a code box with a file name and two icon buttons above (`block-start` plus `border-b`) and a cursor position and a Run button below. The corner-down-left glyph is not drawn yet, so Run wears a play icon.

Icons

shadcn's `input-group-icon`: icons as addons, at the start, at the end, or two together. They are drawn glyphs, not fonts, so each one is a slightly different line.

Custom control

shadcn's `input-group-custom`: any control can be the group's field if it carries `data-slot="input-group-control"`. The original uses react-textarea-autosize; this one is a plain textarea with `field-sizing: content`, which grows with the text without a package.

API 参考

InputGroup

The group: a `<div role="group">` that is the ink host. It draws the Input's pencil box once (rest), a red one (invalid) and a dashed one (disabled) as additive layers that follow the control in CSS. The control must be a direct child for the theme's own selectors; a deeper control works through `has-[...]` classes. `data-disabled` and `data-invalid` on the group work by hand.

属性类型默认值说明
seedstring | number-Pins the hand: the same seed always draws the same box. Default: derived from useId().

InputGroupAddon

Something beside or above/below the control. It is a role=group; clicking it focuses the control, except when the click lands on a button, link, select or another control inside it.

属性类型默认值说明
align"inline-start" | "inline-end" | "block-start" | "block-end""inline-start"Where it sits. The block alignments stack it above or below the control and make the group grow taller.

InputGroupButton

A Button for an addon: ghost by default. Put it inside an InputGroupAddon (a disabled button directly in the group would make the whole group look disabled).

属性类型默认值说明
size"xs" | "sm" | "icon-xs" | "icon-sm""xs"24 px, 32 px, or the square versions. All Button variants work.

无障碍

  • The group is role="group"; label the CONTROL (a Label with htmlFor, or aria-label), not the group. Addon icons are decorative; put meaningful text in an InputGroupText or give the button an aria-label.
  • Focus stays on real controls: Tab goes through the control and the buttons in the DOM order, with the group's blue ring around the box when the control is focus-visible and each button's own ring when it is.
  • State: `aria-invalid` on the control turns the box red and draws the wavy underline; `disabled` on the control (or `data-disabled="true"` on the group) draws the dashed box. Neither depends on hue alone. Pair invalid with a message and aria-describedby.
  • Windows high contrast replaces the ink by a real border on the group. The drawing is aria-hidden and pointer-events: none.
  • Right-to-left: addons use logical padding and ordering (inline-start is the right side), the wavy underline mirrors, and nothing else needs a twin.

源码

CLI 会复制进你项目的文件。

正在加载源码