# 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.

**Dependencies:** npm: 2 direct, 3 total; registry: 2 direct, 2 total.

Native: iOS stable, Android stable.

## 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.

### Native

**Default**

```text
WerewolfInput(value: name, onValueChange: { name = $0 }, placeholder: "Name")
```

```text
WerewolfInput(value = name, onValueChange = { name = it }, placeholder = "Name")
```

**Clearable search**

```text
WerewolfInput(value: query, onValueChange: { query = $0 }, placeholder: "Search", leadingIcon: Image(systemName: "magnifyingglass"), clearable: true)
```

```text
WerewolfInput(value = query, onValueChange = { query = it }, placeholder = "Search", leadingIcon = { Icon(searchIcon, contentDescription = null) }, clearable = true)
```

**Password**

```text
WerewolfInput(value: password, onValueChange: { password = $0 }, placeholder: "Password", secure: true, showPasswordToggle: true)
```

```text
WerewolfInput(value = password, onValueChange = { password = it }, placeholder = "Password", secure = true, showPasswordToggle = true)
```

**Email keyboard**

```text
WerewolfInput(value: email, onValueChange: { email = $0 }, placeholder: "you@example.com", keyboard: .email)
```

```text
WerewolfInput(value = email, onValueChange = { email = it }, placeholder = "you@example.com", keyboard = WerewolfKeyboard.Email)
```

## 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.

Values: `sm`, `md`, `lg`, `xl`. Default: `md`.

### type

Native input type for single-line text-like fields.

Values: `text`, `email`, `password`, `search`, `tel`, `url`, `number`. Default: `text`.

### keyboard

Which on-screen keyboard to open. The native twin of the web type prop, which also picks the keyboard there.

Values: `default`, `email`, `number`, `phone`, `url`. Default: `default`.

## Examples

### Default

```tsx
<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.

```tsx
<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.

```tsx
<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

```tsx
<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

```tsx
<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

```tsx
<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>
```

### Clearable search

```tsx
<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

```tsx
<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

```tsx
<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

```tsx
<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

| Name | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `size` | `enum` | `sm`, `md`, `lg`, `xl` | `md` | 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. |
| `disabled` | `boolean` |  | `false` | Not interactive. Neutral disabled look. |
| `readOnly` | `boolean` |  | `false` | The value can be read, selected and copied but not edited. Same look as default; keeps the focus ring. |
| `type` | `enum` | `text`, `email`, `password`, `search`, `tel`, `url`, `number` | `text` | Native input type for single-line text-like fields. Only on web. Not generated for iOS and Android. |
| `leadingIcon` | `node` |  |  | 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. |
| `trailingIcon` | `node` |  |  | 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. |
| `leadingText` | `node` |  |  | 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. |
| `trailingText` | `node` |  |  | Fixed text joined to the end of the field, such as a unit (kg, %) or a domain (.com). Same look and reading as leadingText. |
| `invalid` | `boolean` |  | `false` | Sets aria-invalid, which draws the danger border. Pair it with error text in color-text-danger linked through aria-describedby. |
| `value` | `string` |  |  | The text in the field. Pair it with onValueChange; the field keeps no state of its own. Only on iOS, Android. |
| `onValueChange` | `function` |  |  | Called with the new text after every edit. Only on iOS, Android. |
| `placeholder` | `string` |  |  | Hint text shown while the field is empty. On web it is the placeholder attribute. Only on iOS, Android. |
| `keyboard` | `enum` | `default`, `email`, `number`, `phone`, `url` | `default` | Which on-screen keyboard to open. The native twin of the web type prop, which also picks the keyboard there. Only on iOS, Android. |
| `secure` | `boolean` |  | `false` | Hides the text as dots, for a password. With showPasswordToggle the toggle switches it. Only on iOS, Android. |
| `clearable` | `boolean` |  | `false` | A 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. |
| `onClear` | `function` |  |  | Called after the clear button, or Escape in a search field, empties the field. onChange fires first, so a controlled value is already empty. |
| `clearLabel` | `string` |  | `Clear` | Name of the clear button, such as Clear search, for a translated page. |
| `showPasswordToggle` | `boolean` |  | `false` | With 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. |
| `showPasswordLabel` | `string` |  | `Show password` | Name of the show-password toggle, for a translated page. |
| `loading` | `boolean` |  | `false` | A small Spinner at the end while the value is checked or searched. Sets aria-busy on the input; the field stays editable. |
| `loadingLabel` | `string` |  | `Loading` | What the spinner says to a screen reader, such as Checking name. |

Not generated: InputGroup, InputGroupButton, InputGroupAddon.

### Slots

| Name | Required | Description |
| --- | --- | --- |
| `value` | no | Controlled or uncontrolled text value. |

## Anatomy

| Part | Description |
| --- | --- |
| `root` | The input element. Alone, it is the field box. With an icon it fills the group and draws no box of its own. |
| `placeholder` | Hint text shown when the value is empty. Colored with text-secondary, so it reaches 4.5:1 on the raised fill. |
| `group` | The 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. |
| `groupIcon` | The leading or trailing icon inside the group. 16px in sm, md and lg, 20px in xl (DESIGN.md 9.1). Decorative. |
| `addon` | The 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. |
| `groupButton` | A 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. |
| `groupAddon` | InputGroupAddon: 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`

| Keys | Action |
| --- | --- |
| `Tab` | Moves focus to the input and shows the focus ring. |
| `Any printable key` | Inserts text at the caret. |
| `Escape` | In 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

```bash
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](https://www.werewolf-ui.dev/docs/installation.md) for requirements and the alternative registry setup.

```bash
npx werewolf-ui add input --platform ios
npx werewolf-ui add input --platform android
```

For iOS and Android, run `npx werewolf-ui init --platform ios` or `npx werewolf-ui init --platform android` once, then add with `--platform`. See [Installation](https://www.werewolf-ui.dev/docs/installation.md).
