Skip to main content

Input

Collects a single line of user-entered text.

import { Input } from "@/fragments/ui";Source

Preview

<Input label="Name" placeholder="Enter your name" />

Installation

npx @usefragments/cli add input

Writes src/fragments/ui/components/Input plus what it imports, the globals stylesheet, and .fragments/registry-lock.json, then prints the packages to add. No account, no key.

Your own registry: publish from Fragments Cloud and add --registry org/name. Connect a workspace.

Examples

With Value

Starts with a value already in the field.

<Input label="Email" type="email" value="user@example.com" />

With Helper

Supporting text sits under the field.

<Input
  label="Password"
  type="password"
  placeholder="Create a password"
  helperText="Must be at least 8 characters"
/>

Error State

Red border, and helperText becomes the reason.

<Input
  label="Email"
  type="email"
  value="invalid-email"
  error
  helperText="Please enter a valid email address"

Disabled

Dimmed, unfocusable, still shows its value.

<Input label="Username" value="ada.lovelace" disabled />

Required

Asterisk marks the field as mandatory.

<Input
  label="Email"
  type="email"
  placeholder="user@example.com"
  required
/>

Sizes

Three heights: sm, md, lg.

<div style={{ display: 'flex', flexDirection: 'column', gap: '12px', maxWidth: '300px' }}>
  <Input label="Small" size="sm" placeholder="Small input" />
  <Input label="Medium" size="md" placeholder="Medium input" />
  <Input label="Large" size="lg" placeholder="Large input" />
</div>

Bare Input (Field Composition)

Drops the built-in label wrapper so Field owns the layout.

<Input
  withFieldWrapper={false}
  aria-label="Search"
  placeholder="Search..."
  rootProps={{ 'data-demo': 'bare-input-wrapper' }}
/>

Search With Shortcut

Leading icon and a ⌘K hint that focuses the field.

<Input
  aria-label="Search findings"
  placeholder="Search findings..."
  shortcut="⌘K"
  shortcutBehavior="focus-input"
  startAdornment={<MagnifyingGlass aria-hidden="true" />}

With Start Adornment

Prefix sits inside the field, before the text.

<Input
  label="Price"
  placeholder="0.00"
  startAdornment={<span>$</span>}
/>

With End Adornment

Suffix sits inside the field, after the text.

<Input
  label="Weight"
  placeholder="0"
  endAdornment={<span>kg</span>}
/>

API

Component props
Prop
Type
Default
Description
valuestringNot setCurrent input value (controlled)
defaultValuestringNot setDefault value for uncontrolled usage
placeholderstringNot setPlaceholder text shown when empty
typeenumnumbertextemailpasswordtelurltextHTML input type for validation and keyboard
sizeenumsmmdlg"md"Size variant
disabledbooleanfalseWhether the input is interactive
errorbooleanfalseWhether to show error styling
labelstringNot setLabel text displayed above input
requiredbooleanfalseWhether the field is required (shows asterisk)
helperTextstringNot setHelper or error message below input
startAdornmentnodeNot setContent rendered before the input (icon or prefix text)
endAdornmentnodeNot setContent rendered after the input (icon or suffix text)
shortcutstringNot setKeyboard shortcut hint displayed as a visual kbd token inside the input
shortcutBehaviorenumdisplay-onlyfocus-inputdisplay-onlyWhether shortcut hint is visual only or also registers a global focus hotkey
onChangefunctionNot setCalled with new value on change
onValueChangefunctionNot setValue-first change callback alias: (value: string) => void
onBlurfunctionNot set
onFocusfunctionNot set
onKeyDownfunctionNot set
rootPropsobjectNot setHTML attributes applied to the wrapper element
inputStyleobjectNot setInline styles applied directly to the input element
inputClassNamestringNot setClass name applied directly to the input element
withFieldWrapperbooleantrueRender built-in label/helper wrapper (set false for Field composition or bare input rendering)
classNamestringNot setWrapper class name
styleobjectNot setWrapper styles

Accessibility

  • Label is programmatically tied to the input
  • Error text is announced to screen readers
  • Required fields are marked

Guidance

Use when

  • Single-line answers: name, email, password, phone, URL
  • Search fields
  • Short free-form values a list cannot cover

Avoid when

  • Multi-line text (use Textarea)
  • Selecting from predefined options (use Select)
  • Boolean input (use Checkbox or Switch)
  • Date/time input (use DatePicker)
  • TextareaalternativeUse Textarea for multi-line text input
  • SelectalternativeUse Select when choosing from predefined options
  • FieldparentUse Field for advanced form composition and custom controls

Next steps