Skip to content

Design system

Documentation

DesignComponents / Input

Components / Input

Beta

Input

Use Input for single-line text entry. Pair it with Field for a visible label, supporting text, and validation message.

On this page

Examples

Basic entry

A named single-line value with a native input type.

Basic Input

Density

Use sm, default, or lg to match the surrounding form rhythm.

Input size comparison

Controlled value

Feature state owns the value when validation or submission needs it.

Type to test the controlled value.

Controlled Input value

Uncontrolled value

Use defaultValue for a local native form value that does not need mirrored state.

Uncontrolled Input with default value

Disabled, read-only, and invalid

State styling stays paired with a readable label and explanation.

Invalid, read-only, and disabled Input states

When to use

Use Input for short values such as names, URLs, search terms, and identifiers. Use a textarea for multi-line text, a select for a constrained choice, and a specialized control only when the interaction requires it.

Usage

input-basic.tsx
import { Input } from "@phuctech/ui/components/input";

export function Example() {
  return <Input aria-label="Workspace name" placeholder="PhucTech workspace" />;
}

For a form, wrap Input in Field. Use a controlled value when the surrounding feature needs to validate or submit it; use defaultValue for an uncontrolled form field.

States

Input states and guidance
StateGuidance
disabledUse when the control cannot be changed in the current context; explain unexpected unavailability.
readOnlyKeep the value focusable and selectable when people may need to copy it.
aria-invalidSet when validation has failed and connect the error through aria-describedby.
sizeUse sm, md, or lg to match density; this is the visual size, not the native character-count hint.

API

Component API
PropTypeDefaultDescriptionConstraints
size"sm" | "md" | "lg""md"Visual control height and radius.Choose the shared density; use Field for labels and errors.
typeHTMLInputTypeAttribute"text"Native input type.Use the native type that matches the value.
value / defaultValuestring | numberControlled or uncontrolled value model.Do not switch models after mount.
disabledbooleanfalsePrevents editing and interaction.Do not use it to hide validation or required instructions.
readOnlybooleanfalsePrevents edits while keeping the value available.Pair with a clear label.
aria-invalidboolean | "true" | "false"Communicates validation failure.Connect the explanation with aria-describedby.

Tokens

Component tokens
TokenRoleEffective valueUsage
--size-control-*Control heightsm / md / lgThe size prop maps to shared input density.
--radius-*Boundary geometrymd / lgKeeps inputs aligned with Button and other controls.
--color-border-defaultDefault boundarysemantic borderProvides the quiet boundary in both themes.
--focus-ring-*Keyboard focus3px / 2px / semantic focusMakes focus visible without changing layout.

Accessibility

  • Every Input needs a visible label or an explicit accessible name.
  • Use native input types, autocomplete hints, and spellcheck settings when they improve completion.
  • Do not communicate an error through border color alone; provide text and connect it with aria-describedby.

Do and don’t

Do

Use Field for the label and error, then keep the Input responsible for value and native control behavior.

Don’t

Use placeholder text as the only label, switch controlled/uncontrolled models, or hide the error message.

  • Field supplies the label, description, and error relationship.
  • Button handles submit and cancel actions around a form.
  • Accessibility documents the focus and validation contract.