组件

Input

A one-line text field: a pencil box on paper around a real <input>, with blue felt for what you type. It draws its own hover, focus ring, invalid (red pencil and a !), disabled (dashes) and read-only (printed) states.

安装

terminal
npx shadcn@latest add @wobko/input

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

示例

Default

A label and a field. What you type is blue felt; the placeholder is graphite.

States

Filled, invalid (red pencil, a wavy underline and a !), disabled (dashed pencil) and read-only (printed). Hover and Tab into them to see the rest.

Types

Password, number, search, date and file. The number spinners and the search clear button are removed; the file button is a highlighter swatch.

With an icon

className goes to the frame, but padding goes to the input: pl-9 makes room for the pencilled magnifier exactly as it would on a plain shadcn input.

A sign-up form

Real validation: the email field turns red with its message the moment it is wrong, and the form only submits when it is right.

Email field

shadcn's `input-demo`: the bare Input, nothing around it. `type="email"` and a placeholder are all it takes; what you type comes out in blue felt.

Disabled

shadcn's `input-disabled`: `disabled` draws the box in dashed pencil and takes the field out of the tab order and out of the form.

File

shadcn's `input-file`: `type="file"` under a label. The native picker button becomes a highlighter swatch; the file name is the field's own text.

With button

shadcn's `input-with-button`: an Input and an outline Button side by side in a flex row. Two separate drawings that line up, not one shared box (InputGroup does that).

With label

shadcn's `input-with-label`: a Label above the field in a grid, tied to it by `htmlFor` and `id`, so a click on the word puts the cursor in the box.

With help text

shadcn's `input-with-text`: a line of muted help under the field. Here it is joined to the input with `aria-describedby`, which the original leaves to you.

API 参考

Input

A <span data-slot="input-frame"> (the drawn box: it owns the size, the drawing and the state) around <input data-slot="input">. Everything you pass goes to the <input>, as in shadcn, and ref is the input. className and style go to the frame, so width, height, margin, flex and grid placement, font size and text color work as they always did; padding, resize-* and variants like placeholder: or file: are moved onto the input, which keeps the whole box clickable and the text inset exactly as in shadcn.

属性类型默认值说明
classNamestring-Classes for the frame (layout, height, font, text color). Padding utilities and control-only variants (placeholder:, file:, selection:, autofill:, focus:, disabled:) are applied to the <input> instead.
inputClassNamestring-Classes appended to the <input> itself, after the ones moved there from className.
seedstring | number-Pins the hand: the same seed always draws the same box, also across remounts. Default: derived from useId().
disabledbooleanfalseA real disabled input, drawn as dashed pencil on a pale wash. Under a disabled <fieldset> the input is still disabled, but the box is not redrawn.
readOnlybooleanfalseFocusable and selectable, drawn as a printed field: a pale wash and one quiet pencil line, no hover.
aria-invalidboolean | "true" | "false"-true draws the red-pencil box, the wavy underline and the ! mark (and reserves room for it at the end of the line). Set it from your validation, as with shadcn.

无障碍

  • A native <input>: label it with <Label htmlFor>, aria-label or aria-labelledby; type, required, pattern, autocomplete and inputmode work as usual.
  • aria-invalid, disabled and readOnly are the real attributes; the drawing follows them. Pair aria-invalid with aria-describedby pointing at the error text.
  • Focus draws a blue felt ring (3:1 or better against paper) when the input is focused by keyboard or click (text fields always match :focus-visible). Before the drawing exists and in Windows high contrast the browser's own outline and a real border are used.
  • The drawing is aria-hidden, pointer-events: none and never focusable. Typed text is blue felt on paper (7:1), placeholders are graphite (6.8:1), disabled text is graphite on a pale wash.
  • 16 px text on every screen size, so iOS does not zoom on focus. Number spinners, the search clear button and the password reveal of Edge are removed; the keyboard behavior (arrow keys, Escape) is untouched.
  • Reduced motion: no fade, no wobble; the field has no hover tilt at all.

源码

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

正在加载源码