Skip to content

    Input

    A single-line text field on a raised fill, in four sizes, with an optional decorative icon or fixed text before or after the value. Text is 16px on touch screens so iOS Safari doesn't zoom in on focus.

    React

    Preview

    Props

    • size
    • disabled
    • type
    • invalid
    • clearable
    • clearLabel
    • showPasswordToggle
    • showPasswordLabel
    • loading
    • loadingLabel
    • label
    • placeholder
    • defaultValue
    • icon
    • aria-invalid
    import { Input } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="preview-input" className="text-sm text-text-secondary">Email</label>
      <Input id="preview-input" placeholder="you@example.com" />
    </div>

    Usage

    When to use

    • Single-line text the user types: a name, an email address, a search term, a number.
    • Values the user can copy but not edit, such as an API key, with readOnly.
    • A field whose icon says what goes in, such as a magnifying glass for search, with leadingIcon.

    When not to use

    • Text over several lines. Use Textarea.
    • Picking one value from a known list. Use Select.
    • A disabled field for a value the user should still read or copy. Use readOnly instead, so the field stays focusable and the value can be copied.

    Platform support

    What each platform has, from the spec. A selected platform is highlighted.

    NameWebiOSAndroidNote
    sizeYesYesYes
    disabledYesYesYes
    readOnlyYesYesYes
    typeYesNoNoOnly on web. Not generated for iOS and Android.
    leadingIconYesYesYes
    trailingIconYesYesYes
    leadingTextYesYesYes
    trailingTextYesYesYes
    invalidYesYesYes
    valueNoYesYesOnly on iOS, Android.
    onValueChangeNoYesYesOnly on iOS, Android.
    placeholderNoYesYesOnly on iOS, Android.
    keyboardNoYesYesOnly on iOS, Android.
    secureNoYesYesOnly on iOS, Android.
    clearableYesYesYes
    onClearYesYesYes
    clearLabelYesYesYes
    showPasswordToggleYesYesYes
    showPasswordLabelYesYesYes
    loadingYesYesYes
    loadingLabelYesYesYes

    Variants

    size

    Height from size-element-*: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse. On touch, md grows to 36px, lg to 44px and xl to 48px; sm does not, so don't use sm on touch-first screens.

    • sm

    • mddefault

    • lg

    • xl

    import { Input } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="preview-input-size-sm" className="text-sm text-text-secondary">Email</label>
      <Input id="preview-input-size-sm" size="sm" placeholder="you@example.com" />
    </div>
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="preview-input-size-md" className="text-sm text-text-secondary">Email</label>
      <Input id="preview-input-size-md" placeholder="you@example.com" />
    </div>
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="preview-input-size-lg" className="text-sm text-text-secondary">Email</label>
      <Input id="preview-input-size-lg" size="lg" placeholder="you@example.com" />
    </div>
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="preview-input-size-xl" className="text-sm text-text-secondary">Email</label>
      <Input id="preview-input-size-xl" size="xl" placeholder="you@example.com" />
    </div>

    Examples

    Default

    import { Input } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="email" className="text-sm text-text-secondary">Email</label>
      <Input id="email" type="email" placeholder="you@example.com" />
    </div>

    With an icon

    The icon is decorative; the visible label names the field.

    import { IconSearch } from "@tabler/icons-react"
    import { Input } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="search-files" className="text-sm text-text-secondary">Search files</label>
      <Input id="search-files" type="search" placeholder="Name or extension" leadingIcon={<IconSearch size={16} />} />
    </div>

    With fixed text

    The fixed text is part of the value's meaning, so the input is described by it.

    werewolf.dev/
    kg
    import { Input } from "@/components/ui/input"
    
    <div className="flex w-full max-w-sm flex-col gap-md">
      <div className="flex w-96 max-w-full flex-col gap-xs">
        <label htmlFor="workspace-url" className="text-sm text-text-secondary">Workspace URL</label>
        <Input id="workspace-url" leadingText="werewolf.dev/" defaultValue="acme" />
      </div>
      <div className="flex w-96 max-w-full flex-col gap-xs">
        <label htmlFor="weight" className="text-sm text-text-secondary">Weight</label>
        <Input id="weight" type="number" inputMode="decimal" trailingText="kg" defaultValue="12" />
      </div>
    </div>

    Disabled

    import { Input } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="workspace" className="text-sm text-text-secondary">Workspace</label>
      <Input id="workspace" disabled defaultValue="Personal" />
    </div>

    Readonly

    import { IconLock } from "@tabler/icons-react"
    import { Input } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="api-key" className="text-sm text-text-secondary">API key</label>
      <Input id="api-key" readOnly defaultValue="wolf_sk_4f9a..." trailingIcon={<IconLock size={16} />} />
    </div>

    Invalid

    Enter an email like you@example.com.

    import { Input } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="signup-email" className="text-sm text-text-secondary">Email</label>
      <Input id="signup-email" type="email" invalid aria-describedby="signup-email-error" defaultValue="not-an-email" />
      <p id="signup-email-error" className="text-sm text-text-danger">Enter an email like you@example.com.</p>
    </div>
    import { IconSearch } from "@tabler/icons-react"
    import { Input } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="clear-search" className="text-sm text-text-secondary">Search</label>
      <Input id="clear-search" type="search" leadingIcon={<IconSearch size={16} />} clearable clearLabel="Clear search" defaultValue="werewolf" />
    </div>

    Show password

    import { Input } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="show-password" className="text-sm text-text-secondary">Password</label>
      <Input id="show-password" type="password" showPasswordToggle defaultValue="hunter22" />
    </div>

    Loading

    Checking username
    import { Input } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="handle" className="text-sm text-text-secondary">Username</label>
      <Input id="handle" loading loadingLabel="Checking username" defaultValue="joey" />
    </div>

    Input group

    import { IconCopy } from "@tabler/icons-react"
    import { Input, InputGroup, InputGroupButton } from "@/components/ui/input"
    
    <div className="flex w-96 max-w-full flex-col gap-xs">
      <label htmlFor="invite-link" className="text-sm text-text-secondary">Invite link</label>
      <InputGroup>
        <Input id="invite-link" readOnly defaultValue="https://werewolf.dev/i/7f3k" />
        <InputGroupButton iconOnly aria-label="Copy link">
          <IconCopy size={16} aria-hidden="true" />
        </InputGroupButton>
      </InputGroup>
    </div>

    Do and don't

    Do

    • Always pair the input with a visible label (htmlFor / id).
    • Match the input size to the button next to it: md in forms, sm only in dense mouse-first UI (table filters, toolbars), lg or xl for the single main field of a screen (search hero, sign-in on mobile).
    • Invalid: aria-invalid="true", the danger border, plus error text in color-text-danger linked with aria-describedby. Never color alone.
    • Readonly: native readOnly, same look as default, still focusable with the focus ring. Use it for values the user can copy but not edit (API key, generated URL).
    • Keep the danger border while focused; the halo is drawn outside it.
    • Use leadingIcon for an icon that says what kind of value goes in: a magnifying glass for search, an envelope for email.
    • Pass the icon with size and that match the input size: 16 in sm, md and lg, 20 in xl.
    • Use leadingText or trailingText for a fixed part of the value the user does not type: https://, a currency, a unit. Keep it short, one word or symbol.

    Don't

    • Don't use placeholder as the label or for required info; it disappears on typing.
    • Don't use size sm on touch-first screens. On touch md is already 36px, lg 44px and xl 48px.
    • Don't use disabled for values the user should still read or copy; use readOnly.
    • Don't add a hover border change. border-control already marks the field.
    • Don't drop below font-size-input or restyle colors through className.
    • Don't let an icon carry meaning alone (a check mark for valid, a warning for invalid). Say it in text linked with aria-describedby.
    • Don't put buttons or links in leadingIcon or trailingIcon. The icons are decorative and hidden from screen readers.

    Props

    NameTypeValuesDefaultDescription
    sizeenumsm | md | lg | xlmdHeight from size-element-*: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse. On touch, md grows to 36px, lg to 44px and xl to 48px; sm does not, so don't use sm on touch-first screens.
    disabledboolean-falseNot interactive. Neutral disabled look.
    readOnlyboolean-falseThe value can be read, selected and copied but not edited. Same look as default; keeps the focus ring.
    typeenumtext | email | password | search | tel | url | numbertextNative input type for single-line text-like fields. Only on web. Not generated for iOS and Android.
    leadingIconnode--Decorative Tabler icon before the text, such as a magnifying glass in a search field. Pass size and: 16 in sm, md and lg, 20 in xl.
    trailingIconnode--Decorative Tabler icon after the text, such as a lock on a readonly value. Same size rule as leadingIcon. Not for buttons: use clearable, showPasswordToggle or an InputGroupButton.
    leadingTextnode--Fixed text joined to the start of the field, such as https://, a domain or a currency. Drawn as a sunken segment split from the value by a line; the input is described by it, so a screen reader reads it with the field.
    trailingTextnode--Fixed text joined to the end of the field, such as a unit (kg, %) or a domain (.com). Same look and reading as leadingText.
    invalidboolean-falseSets aria-invalid, which draws the danger border. Pair it with error text in color-text-danger linked through aria-describedby.
    valuestring--The text in the field. Pair it with onValueChange; the field keeps no state of its own. Only on iOS, Android.
    onValueChangefunction--Called with the new text after every edit. Only on iOS, Android.
    placeholderstring--Hint text shown while the field is empty. On web it is the placeholder attribute. Only on iOS, Android.
    keyboardenumdefault | email | number | phone | urldefaultWhich on-screen keyboard to open. The native twin of the web type prop, which also picks the keyboard there. Only on iOS, Android.
    secureboolean-falseHides the text as dots, for a password. With showPasswordToggle the toggle switches it. Only on iOS, Android.
    clearableboolean-falseA clear button at the end while the field has a value. It empties the field, calls onClear and puts focus back in the input. In a search field Escape clears too.
    onClearfunction--Called after the clear button, or Escape in a search field, empties the field. onChange fires first, so a controlled value is already empty.
    clearLabelstring-ClearName of the clear button, such as Clear search, for a translated page.
    showPasswordToggleboolean-falseWith type password only: a toggle button at the end that shows the password as text. Its name stays the same and aria-pressed says whether the password is shown.
    showPasswordLabelstring-Show passwordName of the show-password toggle, for a translated page.
    loadingboolean-falseA small Spinner at the end while the value is checked or searched. Sets aria-busy on the input; the field stays editable.
    loadingLabelstring-LoadingWhat the spinner says to a screen reader, such as Checking name.

    Not generated: InputGroup, InputGroupButton, InputGroupAddon.

    Slots

    NameRequiredDescription
    valuenoControlled or uncontrolled text value.

    Anatomy

    PartDescription
    rootThe input element. Alone, it is the field box. With an icon it fills the group and draws no box of its own.
    placeholderHint text shown when the value is empty. Colored with text-secondary, so it reaches 4.5:1 on the raised fill.
    groupThe field box when an icon or fixed text is set: a wrapper with the same fill, border, radius and height as the input alone. It shows the input's focus, disabled look and danger border through :has(). className lands here.
    groupIconThe leading or trailing icon inside the group. 16px in sm, md and lg, 20px in xl (DESIGN.md 9.1). Decorative.
    addonThe leadingText or trailingText segment: sunken fill, text-secondary, a border-border line on the side that faces the value, edge to edge in the group.
    groupButtonA clear button, the show-password toggle or an InputGroupButton inside the group: a size-inline-md (24px) ghost button on radius-inner with a ::before hit area of size-target-min. Icon 16px, 20px in xl.
    groupAddonInputGroupAddon: a real control or a hint such as a Kbd next to the input inside an InputGroup. Not hidden from screen readers.

    Accessibility

    Role: textbox

    KeysAction
    TabMoves focus to the input and shows the focus ring.
    Any printable keyInserts text at the caret.
    EscapeIn a clearable search field, clears the value and keeps focus.
    • Pair with a visible label (htmlFor / id). Placeholder alone is not a label.
    • Disabled uses the native disabled attribute, so the input leaves the tab order.
    • Readonly uses the native readOnly attribute: still focusable and in the tab order, the value can be selected and copied.
    • Invalid uses aria-invalid="true" plus visible error text in color-text-danger linked with aria-describedby.
    • font-size-input is 14px on mouse and 16px on touch so iOS Safari does not zoom the page on focus.
    • leadingIcon and trailingIcon are decorative (aria-hidden). The label and the text carry the meaning, so a screen reader hears the same field with or without them.
    • A press on an icon or the padding of the group focuses the input, like a press on the field itself.
    • The clear button, the show-password toggle and InputGroupButton are real buttons in the tab order after the input, each with a name. The show-password toggle keeps its name and reports its state with aria-pressed.
    • loading sets aria-busy on the input and the Spinner has role status with its own label, so the wait is announced.

    Install

    npx werewolf-ui add input

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.