Skip to content
All components
Forms

Input

Collect a short, single-line value through a native input, with the type, keyboard and autofill hints the value needs.

A text field with hover, focus, disabled and invalid states.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add input

Then import it from @/components/ui/input. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

With label

Compose an input with a programmatically associated label. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Input } from "@/components/ui/input"

import { Label } from "@/components/ui/label"

export function InputWithLabel() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <div className="flex flex-col gap-1.5">
        <Label htmlFor="input-demo-email">Email</Label>
        <Input id="input-demo-email" type="email" autoComplete="email" placeholder="you@example.com" />
      </div>
    </div>
  )
}

Invalid

Associate an invalid input with its error text. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldError, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"

export function InputInvalid() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-invalid`}>Billing email</FieldLabel>
        <Input
          id={`${id}-invalid`}
          type="email"
          autoComplete="email"
          defaultValue="billing@example"
          aria-invalid
          aria-describedby={`${id}-invalid-error`}
        />
        <FieldError id={`${id}-invalid-error`}>
          Enter an email address in the format name@example.com.
        </FieldError>
      </Field>
    </div>
  )
}

Disabled

Inspect the unavailable control using its real disabled semantics. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

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

export function InputDisabled() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-off`}>Coupon code</FieldLabel>
        <Input id={`${id}-off`} disabled aria-describedby={`${id}-off-hint`} />
        <FieldDescription id={`${id}-off-hint`}>
          Coupons can be added after you choose a plan.
        </FieldDescription>
      </Field>
    </div>
  )
}

With hint

Connect an input to a hint that states the expected format before typing. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

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

export function InputWithHint() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-username`}>Username</FieldLabel>
        <Input
          id={`${id}-username`}
          autoComplete="username"
          autoCapitalize="none"
          spellCheck={false}
          aria-describedby={`${id}-username-hint`}
        />
        <FieldDescription id={`${id}-username-hint`}>
          3 to 20 characters: letters, numbers and hyphens.
        </FieldDescription>
      </Field>
    </div>
  )
}

Read only

Keep input content readable and focusable while preventing text edits. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

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

export function InputReadOnly() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-account`}>Account ID</FieldLabel>
        <Input
          id={`${id}-account`}
          readOnly
          defaultValue="ACCT-48213"
          aria-describedby={`${id}-account-hint`}
        />
        <FieldDescription id={`${id}-account-hint`}>
          Share this ID when you contact support.
        </FieldDescription>
      </Field>
    </div>
  )
}

Mobile keyboards

Request the right on-screen keyboard and autofill with type, inputMode and autoComplete. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

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

export function InputMobileKeyboards() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <div className="flex flex-col gap-4">
        <Field>
          <FieldLabel htmlFor={`${id}-phone`}>Phone number</FieldLabel>
          <Input
            id={`${id}-phone`}
            type="tel"
            autoComplete="tel"
            aria-describedby={`${id}-phone-hint`}
          />
          <FieldDescription id={`${id}-phone-hint`}>
            Include the country code if you are outside the US.
          </FieldDescription>
        </Field>
        <Field>
          <FieldLabel htmlFor={`${id}-amount`}>Amount</FieldLabel>
          <Input
            id={`${id}-amount`}
            inputMode="decimal"
            autoComplete="off"
            aria-describedby={`${id}-amount-hint`}
          />
          <FieldDescription id={`${id}-amount-hint`}>
            Up to two decimal places, for example 49.90.
          </FieldDescription>
        </Field>
      </div>
    </div>
  )
}

Width hint

Size the input to the length of the expected value. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

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

export function InputWidthHint() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-postal`}>Postal code</FieldLabel>
        <Input
          id={`${id}-postal`}
          autoComplete="postal-code"
          className="max-w-40"
          aria-describedby={`${id}-postal-hint`}
        />
        <FieldDescription id={`${id}-postal-hint`}>
          Used to calculate shipping.
        </FieldDescription>
      </Field>
    </div>
  )
}

Sizes

Compare the sm, md and lg input sizes. size changes height and text size and replaces the native size attribute. Set width with layout classes.

"use client"

import * as React from "react"

import { Field, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"

export function InputSizes() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <div className="flex flex-col gap-4">
        {(["sm", "md", "lg"] as const).map((size) => (
          <Field key={size}>
            <FieldLabel htmlFor={`${id}-size-${size}`}>
              {size === "sm" ? "Small" : size === "md" ? "Medium" : "Large"}
            </FieldLabel>
            <Input id={`${id}-size-${size}`} size={size} placeholder="Project name" />
          </Field>
        ))}
      </div>
    </div>
  )
}

Leading icon

Add a decorative leading icon with InputGroup. The search icon is decorative; the visible label names the input and the group owns the focus ring.

"use client"

import { SearchIcon } from "lucide-react"
import * as React from "react"

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

import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group"

export function InputLeadingIcon() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-search`}>Search members</FieldLabel>
        <InputGroup>
          <InputGroupAddon>
            <SearchIcon aria-hidden="true" />
          </InputGroupAddon>
          <InputGroupInput id={`${id}-search`} type="search" placeholder="Name or email" />
        </InputGroup>
      </Field>
    </div>
  )
}

Leading select

Combine a leading Select with an input. The country code Select has its own accessible name, so both controls are named and reachable in order.

"use client"

import * as React from "react"

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

import { InputGroup, InputGroupInput } from "@/components/ui/input-group"

import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"

export function InputLeadingSelect() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-phone-number`}>Phone number</FieldLabel>
        <InputGroup className="ps-1">
          <Select defaultValue="us">
            <SelectTrigger
              aria-label="Country code"
              className="h-8 w-auto shrink-0 gap-1 border-transparent px-2 shadow-none hover:border-transparent focus-visible:border-transparent focus-visible:shadow-none focus-visible:outline-2 focus-visible:outline-primary-base"
            >
              <SelectValue />
            </SelectTrigger>
            <SelectContent>
              <SelectItem value="us">US +1</SelectItem>
              <SelectItem value="uk">UK +44</SelectItem>
              <SelectItem value="ar">AR +54</SelectItem>
              <SelectItem value="de">DE +49</SelectItem>
            </SelectContent>
          </Select>
          <span aria-hidden="true" className="h-5 w-px shrink-0 bg-soft-200" />
          <InputGroupInput id={`${id}-phone-number`} type="tel" autoComplete="tel-national" />
        </InputGroup>
      </Field>
    </div>
  )
}

Trailing button

Attach a trailing action button to an input. The copy button is a real Button inside the group, reachable after the read-only input.

"use client"

import { CopyIcon } from "lucide-react"
import * as React from "react"

import { Button } from "@/components/ui/button"
import { Field, FieldLabel } from "@/components/ui/field"

import { InputGroup, InputGroupInput } from "@/components/ui/input-group"

export function InputTrailingButton() {
  const id = React.useId()
  
  const [copied, setCopied] = React.useState(false)

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-invite`}>Invite link</FieldLabel>
        <InputGroup className="pe-1">
          <InputGroupInput id={`${id}-invite`} readOnly defaultValue="https://example.com/join/8F2KQ" />
          <Button
            size="xs"
            intent="neutral"
            emphasis="stroke"
            className="shrink-0"
            onClick={() => setCopied(true)}
          >
            <CopyIcon />
            {copied ? "Copied" : "Copy"}
          </Button>
        </InputGroup>
      </Field>
    </div>
  )
}

Number stepper

Adjust a number with decrement and increment buttons. The step buttons are labelled, point to the input with aria-controls and disable at the limits; typing still works.

"use client"

import { MinusIcon, PlusIcon } from "lucide-react"
import * as React from "react"

import { Button } from "@/components/ui/button"
import { Field, FieldLabel } from "@/components/ui/field"

import { InputGroup, InputGroupInput } from "@/components/ui/input-group"

export function InputNumberStepper() {
  const id = React.useId()
  const [seats, setSeats] = React.useState(5)
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-seats`}>Seats</FieldLabel>
        <InputGroup className="max-w-40 px-1">
          <Button
            iconOnly
            size="xs"
            intent="neutral"
            emphasis="ghost"
            aria-label="Remove one seat"
            aria-controls={`${id}-seats`}
            disabled={seats <= 1}
            onClick={() => setSeats((current) => Math.max(1, current - 1))}
          >
            <MinusIcon />
          </Button>
          <InputGroupInput
            id={`${id}-seats`}
            type="number"
            inputMode="numeric"
            min={1}
            max={50}
            value={seats}
            onChange={(event) => {
              const next = Number(event.target.value)
              if (!Number.isNaN(next)) setSeats(Math.min(50, Math.max(1, next)))
            }}
            className="text-center [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none"
          />
          <Button
            iconOnly
            size="xs"
            intent="neutral"
            emphasis="ghost"
            aria-label="Add one seat"
            aria-controls={`${id}-seats`}
            disabled={seats >= 50}
            onClick={() => setSeats((current) => Math.min(50, current + 1))}
          >
            <PlusIcon />
          </Button>
        </InputGroup>
      </Field>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Input

Collect a short value through a native input control.

Input props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
size"sm" | "md" | "lg" | null | undefined"md"Control height and text size: sm (36px), md (40px) or lg (48px). Replaces the native size attribute; set width with layout classes. Defaults to md.
Inherited props (32)
Input inherited props
PropTypeDefaultDescription
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
patternstring | undefined—Native input validation pattern. Provide readable format guidance and associated validation feedback.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
refReact.Ref<HTMLInputElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLInputElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLInputElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLInputElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLInputElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLInputElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
altstring | undefined—Text alternative for the image. Identify informative images; use an empty alternative only when the image is genuinely decorative.
srcstring | undefined—Image source URL. Supply alternative text appropriate to whether the image conveys identity or is decorative.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
namestring | undefined—Name used by the control's form submission or primitive form integration.
typeReact.HTMLInputTypeAttribute | undefined—Native HTML input type. Choose the type appropriate to the value being collected.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
multipleboolean | undefined—Allow multiple values where the native element or primitive supports them, using its source-defined value shape.
checkedboolean | undefined—Current checked state. Apply the requested value from onCheckedChange when the parent owns this state.
autoCompleteReact.HTMLInputAutoCompleteAttribute | undefined—Native autocomplete hint appropriate to the field's actual purpose.
maxstring | number | undefined—Maximum supported numeric value.
maxLengthnumber | undefined—Maximum allowed text length for native input or code entry.
minstring | number | undefined—Minimum supported numeric value.
minLengthnumber | undefined—Minimum allowed text length for native validation.
placeholderstring | undefined—Prompt shown before a value is selected or entered. Supply an accessible label separately.
readOnlyboolean | undefined—Prevent value editing while preserving readable content. Read-only behavior differs from disabled behavior.
requiredboolean | undefined—Mark this control as required using its native or primitive semantics. Consumers own contextual validation feedback.
stepstring | number | undefined—Numeric increment used for slider or native input changes.

Accessibility & usage

From registry/ui/input.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • A single-line value people type: names, email addresses, phone numbers, search terms, codes, amounts.
  • Inside Field (or FormItem with Form) so the label, hint or error and the invalid state are associated with the control.
  • Read-only values people may need to select or copy, with readOnly instead of disabled so they stay focusable.

When not to use

  • Text that may run over one line, such as comments or descriptions.
  • Choosing from a known, short set of values; typing invites spelling variants and errors.
  • Dates people pick relative to a calendar, or one-time codes split into slots.

Anatomy

Input
The native input element. size is sm (36px), md (40px, default) or lg (48px) and replaces the native size attribute. Every other native attribute (type, inputMode, autoComplete, required, readOnly, maxLength, pattern) passes through unchanged.
Label (Field label)
A separate Label or FieldLabel whose htmlFor matches the input id; the component does not render one.
Hint or error
A FieldDescription or FieldError with an id referenced from aria-describedby; aria-invalid switches the border to the error role.
Affixes (composition)
Leading icons, a leading Select, a trailing Button or step buttons are composed with InputGroup, which owns the border and focus ring. Each nested control keeps its own accessible name.

Keyboard & interaction

  • Native text editing, selection, autofill and spell checking come from the browser; the component adds no keyboard handling.
  • Focus is shown with the border and focus shadow on keyboard focus (focus-visible); aria-invalid swaps both to the error role.
  • Disabled inputs are removed from the Tab order and ignore pointer input; readOnly inputs stay focusable and selectable.
  • Validate when focus leaves the field or on submit; once an error is shown, re-check as the person types so it clears as soon as the value is fixed.
  • On submit, move focus to the first invalid field (Form with React Hook Form does this when the field ref is passed).

Responsive behavior

  • The input is full width with min-w-0, so it shrinks inside flex rows and never forces horizontal scrolling at 320 CSS px.
  • Match width to the expected value on wide screens (a postal code or CVC field narrower than an address field) with a max-width class; let it return to full width on narrow screens if needed.
  • Height is 40 CSS px, above the 24 px minimum target; keep the label above the field so it never competes for width on phones.
  • Choose type and inputMode for the on-screen keyboard: email, tel and url types, inputMode="numeric" for digit-only codes, inputMode="decimal" for amounts.
  • At 200% text size the value and placeholder must stay readable; do not lock the height with a fixed line count in custom styles.

Content guidelines

  • Label: a short noun phrase for the value ('Work email', 'Postal code'), in sentence case, without a trailing colon.
  • Hint: state the expected format or constraint before people type ('3 to 20 characters: letters, numbers and hyphens'); keep it visible, not only in a tooltip.
  • Error: say what is wrong and how to fix it, in the same terms as the hint ('Enter an email address in the format name@example.com'); never only 'Invalid'.
  • Placeholder: optional example of the format; never repeat the label and never put instructions only there.
  • Mark optional fields '(optional)' when most fields are required, or required fields when most are optional; do not rely on color or an unexplained asterisk.
  • Name step buttons by their effect ("Add one seat") and disable them at the limits; keep typing available.

Alternatives

  • Textarea — Multiline or long free-form text.
  • Native select — A known list where the platform picker is fastest, especially on phones.
  • Combobox — A long known list people search by typing, with a guaranteed valid value.
  • Input group — The same input with a unit, prefix, icon or inline button attached.
  • Input OTP — A short verification code entered character by character.
  • Date picker — A date chosen with the help of a calendar.

Resources