# Input

One text-entry field with a label, description and error; `type` picks text, email, url, password, search, number or tel.

- Family: form
- Import: `import { Input } from "@senvenli/react/form";`
- Page: https://design.senvenli.com/docs/components/input
- JSON: https://design.senvenli.com/docs/components/input.json

## Example: A labeled field

The label sits above the field; help text goes under it.

```tsx
import { Input } from "@senvenli/react/form";

export default function Example() {
  return (
    <Input
      label="Work email"
      type="email"
      autoComplete="email"
      placeholder="name@example.com"
      description="We send invoices and receipts here."
    />
  );
}
```

## Examples

### Prefix and suffix

An icon, a unit or a URL part inside the frame.

```tsx
import { Icon } from "@senvenli/react/display";
import { Input } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack space="space-200">
      <Input label="Customer" leading={<Icon name="user" />} defaultValue="Ada Lovelace" />
      <Input label="Workspace URL" leading="https://" trailing=".example.com" valueDir="ltr" defaultValue="acme" />
      <Input label="Hourly rate" variant="numeric" inputMode="decimal" leading="$" trailing="per hour" defaultValue="85.00" />
    </Stack>
  );
}
```

### Invalid

The error says what happened and what to do.

```tsx
import { Input } from "@senvenli/react/form";

export default function Example() {
  return (
    <Input
      label="Work email"
      type="email"
      defaultValue="ada@example"
      isInvalid
      errorMessage="Enter a valid email: name@example.com"
    />
  );
}
```

### Small, read-only and disabled

The smaller size for dense forms, and the two states a value can be locked in.

```tsx
import { Input } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack space="space-200">
      <Input label="Reference" size="small" variant="code" defaultValue="INV-2041" />
      <Input label="Customer ID" variant="code" defaultValue="cus_8f3k2" isReadOnly />
      <Input label="Company" defaultValue="Analytical Engines Ltd" isDisabled />
    </Stack>
  );
}
```

### Password: Signing in

`current-password` lets the password manager fill it; the button shows or hides the value.

```tsx
import { Input } from "@senvenli/react/form";

export default function Example() {
  return <Input type="password" label="Password" autoComplete="current-password" />;
}
```

### Password: Creating a password

The requirements up front, and a strength meter while typing.

```tsx
import { Input } from "@senvenli/react/form";

export default function Example() {
  return (
    <Input type="password"
      label="New password"
      autoComplete="new-password"
      description="At least 10 characters, with a number and a symbol."
      showStrength
      defaultValue="orchid-ladder"
    />
  );
}
```

### Password: Invalid

The error says what to do next.

```tsx
import { Input } from "@senvenli/react/form";

export default function Example() {
  return (
    <Input type="password"
      label="Password"
      autoComplete="current-password"
      defaultValue="orchid-ladder"
      isInvalid
      errorMessage="That password is not right. Try again or reset it."
    />
  );
}
```

### Search: Search a list

The placeholder lists what can be searched; `aria-label` names the field.

```tsx
import { Input } from "@senvenli/react/form";

export default function Example() {
  return <Input type="search" aria-label="Search customers" placeholder="Name, email or order number" />;
}
```

### Search: Filtering as you type

Controlled: the list follows the text, and Esc or the clear button empties it.

```tsx
import { Text } from "@senvenli/react/display";
import { Input } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";
import { useState } from "react";

const CUSTOMERS = ["Ada Lovelace", "Alan Turing", "Grace Hopper", "Katherine Johnson", "Margaret Hamilton"];

export default function Example() {
  const [query, setQuery] = useState("");
  const matches = CUSTOMERS.filter((name) => name.toLowerCase().includes(query.trim().toLowerCase()));
  return (
    <Stack space="space-150">
      <Input type="search" aria-label="Search customers" placeholder="Customer name" value={query} onChange={setQuery} />
      {matches.length > 0 ? (
        <Stack as="ul" space="space-050">
          {matches.map((name) => (
            <li key={name}>
              <Text>{name}</Text>
            </li>
          ))}
        </Stack>
      ) : (
        <Text tone="subtle">No customers match “{query}”.</Text>
      )}
    </Stack>
  );
}
```

### Search: Label, shortcut and small size

A visible label, and a key hint shown while the field is empty.

```tsx
import { Input } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack space="space-200">
      <Input type="search" label="Search invoices" placeholder="Number, customer or amount" shortcut="/" />
      <Input type="search" aria-label="Search projects" placeholder="Project name" size="small" />
    </Stack>
  );
}
```

### Number: A quantity

The stepper suits small whole numbers; the range is stated up front.

```tsx
import { Input } from "@senvenli/react/form";

export default function Example() {
  return <Input type="number" label="Seats" description="1–50 seats per workspace." defaultValue={5} minValue={1} maxValue={50} showStepper />;
}
```

### Number: Money

`currency` adds the symbol and keeps the currency's decimals.

```tsx
import { Input } from "@senvenli/react/form";

export default function Example() {
  return <Input type="number" label="Invoice amount" currency="USD" defaultValue={1248.5} minValue={0} />;
}
```

### Number: Units and percentages

A suffix for a unit, or `formatOptions` when Intl can print it.

```tsx
import { Input } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack space="space-200">
      <Input type="number" label="Payment terms" trailing="days" defaultValue={30} minValue={0} maxValue={90} description="0–90 days after the invoice date." />
      <Input type="number" label="Discount" formatOptions={{ style: "percent" }} defaultValue={0.15} minValue={0} maxValue={1} isOptional />
    </Stack>
  );
}
```

### Phone: A phone number

Opens on `defaultCountry`; the suggested countries lead the list.

```tsx
import { Input } from "@senvenli/react/form";

export default function Example() {
  return (
    <Input type="tel"
      label="Phone number"
      name="phone"
      defaultCountry="US"
      suggestedCountries={["US", "CA", "GB"]}
      description="We only call about a delivery."
    />
  );
}
```

### Phone: Controlled

The value is E.164; `onChange` also gives the chosen country.

```tsx
import { Text } from "@senvenli/react/display";
import { Input } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";
import { useState } from "react";

export default function Example() {
  const [phone, setPhone] = useState("+442079460958");
  const [country, setCountry] = useState("GB");
  return (
    <Stack space="space-150">
      <Input type="tel"
        label="Billing phone"
        value={phone}
        country={country}
        suggestedCountries={["US", "CA", "GB"]}
        onChange={(value, nextCountry) => {
          setPhone(value);
          setCountry(nextCountry);
        }}
      />
      <Text size="body-small" tone="subtle">
        Stored as {phone || "nothing yet"} ({country})
      </Text>
    </Stack>
  );
}
```

### Phone: Invalid

The error says what a full number looks like.

```tsx
import { Input } from "@senvenli/react/form";

export default function Example() {
  return (
    <Input type="tel"
      label="Phone number"
      defaultCountry="US"
      suggestedCountries={["US", "CA", "GB"]}
      defaultValue="+1415555"
      isInvalid
      errorMessage="Enter the full number with its area code: (415) 555-0132."
    />
  );
}
```

## Guidelines

### When to use it

- Short free text: a name, an email, a code.
- Entering or creating a password.
- Searching or filtering a list or the app.
- Entering a number: a quantity, a price, a percentage.
- Any phone number a person types: sign-up, checkout, contact details.

### Use something else when

- [text-area](https://design.senvenli.com/docs/components/text-area.md): The text may run to several lines.

### Do and avoid

- Errors say what happened and what to do: "Enter a valid email: name@example.com".

## Accessibility

Keyboard:

- Escape: Clears the field.
- Enter: Submits the search.
- Arrow up / down: Increments or decrements by the step.
- Arrow down: Opens the country list from the country button.
- Type: Searches countries by name or calling code.

Built in:

- Label, description and error are announced with the input.
- Required fields show "Fill in this field." after a blur or a submit; your own `errorMessage` replaces it.
- The toggle is named "Show password" / "Hide password".
- Password managers can fill it.
- The clear button is named "Clear".
- Steppers are named "Increase" and "Decrease".
- Formats and parses in the user's locale.
- The country button is named with the country and its code.
- Too short and too long say so in words.
- Required fields show "Fill in this field."

You provide:

- A visible label.
- A label or placeholder that lists what can be searched.
- The range in the label or description.
- suggestedCountries for the markets the form expects.

## API reference

### Input

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| autoCapitalize | `"off" \| "none" \| "on" \| "sentences" \| "words" \| "characters" \| (string & {})` |  | no | Mobile keyboards' capitalization: `none` for e-mail and codes, `characters` for codes, `words` for names. React Aria's TextField forwards it to the input (useTextField reads it); its types leave it out, so it is declared here. |
| aria-invalid | `boolean \| "true" \| "false"` |  | no | Set by a form row that owns the error text (the shared `Field` hands its control `aria-invalid`): the field shows its invalid state as with `isInvalid`, and without an `errorMessage` of its own draws no error row, so the row's message is the only one. It marks the input for assistive tech and draws it invalid only: unlike `isInvalid` it never becomes the input's native validity, so it never blocks a form's submit, and the field's own validation runs as without it. |
| variant | `"text" \| "numeric" \| "code"` |  | no | `code` for codes, references and IDs; `numeric` for money, distance and counts. |
| step | `string \| number \| number` |  | no |  |
| size | `FieldSize` |  | no |  |
| label | `React.ReactNode` |  | no | Always given; the label sits above the field, never inside it. |
| description | `React.ReactNode` |  | no |  |
| errorMessage | `React.ReactNode` |  | no | What happened and what to do ("Enter a valid email: name@example.com"). |
| requiredValidation | `RequiredValidation` |  | no | Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See {@link RequiredValidation} for the whole contract. |
| isOptional | `boolean` |  | no | Shows "(optional)" when most of the form is required. |
| max | `string \| number` |  | no |  |
| min | `string \| number` |  | no | Bounds and step for `type="number"`; prefer NumberField for money and counts that need formatting. |
| placeholder | `string` |  | no |  |
| leading | `React.ReactNode` |  | no | Before the value, inside the frame: text, a unit or currency ("€", "https://"), or `<Icon name="search" />`. |
| trailing | `React.ReactNode` |  | no | After the value, inside the frame: a unit ("kg"), a domain, an icon. |
| actions | `React.ReactNode` |  | no | Extra controls at the end of the frame (`InputAction`). |
| displayCase | `"uppercase"` |  | no | `uppercase` shows the value in capitals (a code: "ab 123" reads "AB 123"); display only . The input's value, `onChange` and the submitted form value stay exactly as typed; the caret and selection follow the text as drawn. Capitals follow the page's language, as CSS `text-transform` does (`lang="tr"`: "i" shows as "İ"), the same as `toLocaleUpperCase` in that locale. The placeholder keeps its own case. Normalise the stored value in the app if it must be capitals. |
| valueDir | `"inherit" \| "ltr"` |  | no | `ltr` keeps the frame, addons and value, left to right on an RTL page: phone numbers, IBANs and card numbers read LTR in every locale ("ME +382 67 412 908", never "908 412 67 ME +382"). The label, help text and error still follow the page. On by default for `type` `url`, `email` and `tel` (the placeholder then aligns LTR too); `inherit` turns that off and follows the page. Pass `ltr` for a domain with URL addons: "https://shop.example.com", never "com. shop.example //:https". |
| type | `"text" \| "url" \| "email" \| "password" \| "search" \| "number" \| "tel"` |  | no | `text` (default), `email` or `url`: the matching keyboard and autofill on phones. |
| radius | `ComponentRadius` |  | no | Corner radius: `none`, `small`, `medium` (the design), `large` or `full`. The provider's default otherwise. |
| showStrength | `boolean` |  | no | Four-segment meter with a word under it (create and reset only). |
| isRevealed | `boolean` |  | no | Controlled visibility: `true` shows the value as text. Leave it out for the default, where the show / hide button alone decides; set it when the app writes a value the person should see (a "Generate" button). |
| onRevealChange | `(revealed: boolean) => void` |  | no | Called with the next visibility when the show / hide button is pressed. |
| shortcut | `string` |  | no | A key hint shown at rest ("/"); the app binds the key. |
| showStepper | `boolean` |  | no | The stepper on the end, for small integers. |
| currency | `string` |  | no | Money: an ISO 4217 code ("EUR"). The symbol becomes a leading addon and the amount keeps two decimals, which reads as the design's "€ 248,00" (symbol first, with a space); Intl's own currency style has no space in tr / me. |
| locale | `string` |  | no | Formats and parses in this locale instead of the provider's (the branch locale). |
| country | `string` |  | no | Controlled ISO country. Left out, it is read from the value, then `defaultCountry`. A shared calling code reads back as the table's first country for it (+1 → US): pass `country` to keep Canada. |
| defaultCountry | `string` |  | no | The country an empty field opens on; by default the locale's region ("de-AT" → AT, "en" → US). |
| suggestedCountries | `readonly string[]` |  | no | ISO codes shown first, above "All countries" (the markets this form expects). |
| onUnsupportedInternationalPaste | `(pasted: string) => void` |  | no | A pasted international number whose country is not offered; the value stays unchanged. |
| labels | `{ country?: (country: string, callingCode: string) => string; countryList?: string; countrySearch?: string; countryEmpty?: (query: string) => React.ReactNode; suggestedCountries?: string; allCountries?: string; }` |  | no | The field's words, already localized; the DS strings in the provider locale by default: - `country`: the country button's name, from the country's name and calling code ("Country: Germany, +49"); - `countryList`: the country list's name, also its popover's ("Country"); - `countrySearch`: the country search box's name ("Search countries"); - `countryEmpty`: the list's empty result for the typed search ("No results for “{query}”."); - `suggestedCountries`: the first section's name, the `suggestedCountries` ("Suggested countries"); - `allCountries`: the header above the rest when suggestions show ("All countries"). |

Behavior props from React Aria:

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| defaultValue | `string \| number` |  | no | The default value (uncontrolled). |
| autoFocus | `boolean` |  | no | Whether the element should receive focus on render. |
| enterKeyHint | `"enter" \| "done" \| "go" \| "next" \| "previous" \| "search" \| "send"` |  | no | An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint). |
| spellCheck | `string` |  | no | An enumerated attribute that defines whether the element may be checked for spelling errors. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck). |
| autoCorrect | `string` |  | no | An attribute that takes as its value a space-separated string that describes what, if any, type of autocomplete functionality the input should provide. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocomplete). |
| inputMode | `"none" \| "search" \| "text" \| "tel" \| "url" \| "email" \| "numeric" \| "decimal"` |  | no | Hints at the type of data that might be entered by the user while editing the element or its contents. See [MDN](https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute). |
| onCopy | `ClipboardEventHandler<HTMLInputElement>` |  | no | Handler that is called when the user copies text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncopy). |
| onCut | `ClipboardEventHandler<HTMLInputElement>` |  | no | Handler that is called when the user cuts text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncut). |
| onPaste | `ClipboardEventHandler<HTMLInputElement>` |  | no | Handler that is called when the user pastes text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/onpaste). |
| onCompositionEnd | `CompositionEventHandler<HTMLInputElement>` |  | no | Handler that is called when a text composition system completes or cancels the current text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionend_event). |
| onCompositionStart | `CompositionEventHandler<HTMLInputElement>` |  | no | Handler that is called when a text composition system starts a new text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event). |
| onCompositionUpdate | `CompositionEventHandler<HTMLInputElement>` |  | no | Handler that is called when a new character is received in the current text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionupdate_event). |
| onFocus | `(e: FocusEvent<HTMLInputElement, Element>) => void \| (e: FocusEvent<Element, Element>) => void` |  | no | Handler that is called when the element receives focus. |
| onBlur | `(e: FocusEvent<HTMLInputElement, Element>) => void \| (e: FocusEvent<Element, Element>) => void \| (event: FocusEvent<HTMLInputElement, Element>) => void` |  | no | Handler that is called when the element loses focus. |
| onChange | `(value: string) => void \| (value: number) => void \| (value: string, country: string) => void` |  | no | Handler that is called when the value changes. |
| onBeforeInput | `FormEventHandler<HTMLInputElement>` |  | no | Handler that is called when the input value is about to be modified. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput_event). |
| onInput | `FormEventHandler<HTMLInputElement>` |  | no | Handler that is called when the input value is modified. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event). |
| onSelect | `ReactEventHandler<HTMLInputElement>` |  | no | Handler that is called when text in the input is selected. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/select_event). |
| isDisabled | `boolean` |  | no | Whether the input is disabled. |
| onFocusChange | `(isFocused: boolean) => void` |  | no | Handler that is called when the element's focus status changes. |
| form | `string` |  | no | The `<form>` element to associate the input with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form). |
| name | `string` |  | no | The name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). |
| value | `string \| number` |  | no | The current value (controlled). |
| excludeFromTabOrder | `boolean` |  | no | Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. |
| isRequired | `boolean` |  | no | Whether user input is required on the input before form submission. |
| isReadOnly | `boolean` |  | no | Whether the input can be selected but not changed by the user. |
| isInvalid | `boolean` |  | no | Whether the value is invalid. |
| validate | `(value: string) => true \| ValidationError \| null \| undefined \| (value: number) => true \| ValidationError \| null \| undefined` |  | no | A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if `validationBehavior="native"`. For realtime validation, use the `isInvalid` prop instead. |
| validationBehavior | `"aria" \| "native"` |  | no | Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA. |
| autoComplete | `string \| "current-password" \| "new-password"` |  | no | Describes the type of autocomplete functionality the input should provide if any. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete). |
| maxLength | `number` |  | no | The maximum number of characters supported by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefmaxlength). |
| minLength | `number` |  | no | The minimum number of characters required by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefminlength). |
| pattern | `string` |  | no | Regex pattern that the value of the input must match to be valid. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefpattern). |
| minValue | `number` |  | no | The smallest value allowed for the input. |
| maxValue | `number` |  | no | The largest value allowed for the input. |
| decrementAriaLabel | `string` |  | no | A custom aria-label for the decrement button. If not provided, the localized string "Decrement" is used. |
| incrementAriaLabel | `string` |  | no | A custom aria-label for the increment button. If not provided, the localized string "Increment" is used. |
| isWheelDisabled | `boolean` |  | no | Enables or disables changing the value with scroll. |

Also takes 88 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### Tokens it reads

`--ds-background-disabled`, `--ds-background-input`, `--ds-background-input-hovered`, `--ds-background-neutral`, `--ds-background-neutral-pressed`, `--ds-background-neutral-subtle-hovered`, `--ds-border`, `--ds-border-bold`, `--ds-border-danger`, `--ds-border-focused`, `--ds-easing-enter`, `--ds-easing-standard`, `--ds-icon-subtle`, `--ds-icon-success`, `--ds-icon-warning`, `--ds-radius-control-medium`, `--ds-radius-full`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-size-control`, `--ds-size-control-compact`, `--ds-size-control-large`, `--ds-size-icon`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-surface-sunken`, `--ds-text`, `--ds-text-danger`, `--ds-text-disabled`, `--ds-text-subtle`, `--ds-text-subtlest`, `--ds-text-success`, `--ds-text-warning`, `--font-ds-mono`

## Related

- [text-area](https://design.senvenli.com/docs/components/text-area.md)
- [field](https://design.senvenli.com/docs/components/field.md)
- [badge](https://design.senvenli.com/docs/components/badge.md)
