# Input (/docs/native/components/input)

<Preview id="input/states/live-validation" title={null} />

## Installation [#installation]

<ComponentInstall name="input" />

## Usage [#usage]

```tsx title="app/index.tsx"
import { Input } from "@/components/ui/input";
import { useState } from "react";
import { View } from "react-native";

export default function Example() {
  const [email, setEmail] = useState("");

  return (
    <View className="flex-1 justify-center p-4">
      <Input value={email} onChangeText={setEmail} placeholder="you@example.com" />
    </View>
  );
}
```

## Variants [#variants]

Use the `variant` prop to change how the box is painted.

<Preview id="input/variants/at-rest" />

```tsx
<Input variant="primary" />
<Input variant="secondary" />
```

## Sizes [#sizes]

One axis drives the box height, the value's type scale and a decorator's icon step.

<Preview id="input/sizes/sizes" />

```tsx
<Input size="sm" />
<Input size="md" />
<Input size="lg" />
```

## Groups [#groups]

Use `Input.Group` to put a prefix or a suffix inside the field's own border.

<Preview id="input/group/icons" />
<Preview id="input/group/text-affixes" />
<Preview id="input/group/controls" />

```tsx
<Input.Group>
  <Input.Group.Prefix>$</Input.Group.Prefix>
  <Input value={amount} onChangeText={setAmount} keyboardType="decimal-pad" />
  <Input.Group.Suffix>NZD</Input.Group.Suffix>
</Input.Group>
```

`variant`, `size`, `isInvalid` and `isDisabled` live on the group, and an `Input` inside one reads
them from context. Pressing anywhere on the group focuses the field; a `Button` inside a decorator
still receives its own press.

### Decorative and interactive decorators [#decorative-and-interactive-decorators]

A decorator holding only bare text and `Icon`s is decorative: screen readers skip it and a tap on
it falls through to the group, which focuses the field. Anything else — a `Button`, a custom
view — stays reachable. Pass `isDecorative` to override either way. When the affix carries
meaning, say it in the field's `accessibilityLabel`.

<Preview id="input/group/decorative" />

```tsx
<Input.Group>
  <Input accessibilityLabel="Discount, percent" inputMode="decimal" />
  <Input.Group.Suffix>
    <Icon icon={IconPercent} />
  </Input.Group.Suffix>
</Input.Group>
```

### Group buttons [#group-buttons]

`Input.Group.Button` is a `Button` sized one step below the box, squared when it holds only an
icon, and disabled with the group without fading twice. Its press is its own. Name an icon-only one
with `accessibilityLabel`; development builds warn when it is missing.

<Preview id="input/group/group-button" />

```tsx
<Input.Group>
  <Input value={query} onChangeText={setQuery} placeholder="Search" />
  <Input.Group.Button accessibilityLabel="Clear" onPress={() => setQuery("")}>
    <Icon icon={IconCrossSmall} />
  </Input.Group.Button>
</Input.Group>
```

### Separators [#separators]

`Input.Group.Separator` draws a hairline. Its direction comes from where it is written: in the row
it is vertical, between a block and the row it is horizontal and meets the border on both sides.

<Preview id="input/group/separator" />

```tsx
<Input.Group size="lg">
  <Input.Group.Prefix>$</Input.Group.Prefix>
  <Input.Group.Separator />
  <Input inputMode="decimal" placeholder="0.00" />
</Input.Group>
```

### Blocks and Textarea [#blocks-and-textarea]

`Input.Group.Block` adds a full-width section above (`position="start"`) or below
(`position="end"`) the field, inside the same border and focus ring. A `Textarea` can take the
field's place, which makes a message composer one box. A block must be a direct child of the group.

<Preview id="input/group/composer" />

```tsx
<Input.Group>
  <Textarea autoGrow rows={2} placeholder="Write a message" />
  <Input.Group.Separator />
  <Input.Group.Block position="end">
    <Input.Group.Button variant="secondary" onPress={send}>Send</Input.Group.Button>
  </Input.Group.Block>
</Input.Group>
```

Disabling or invalidating the group reaches every part at once: the box fades once, decorators and
block text turn destructive, and every `Input.Group.Button` goes inert.

## States [#states]

The two state axes resolve `Input.Group` → the `Input`'s own prop → the enclosing `Field`, and both
are `??` chains, so an explicit `false` is a value rather than an absence.

<Preview id="input/variants/invalid" />
<Preview id="input/states/live-validation" />

```tsx
<Input isInvalid />
<Input isDisabled />
```

## Placeholder, caret and selection colours [#placeholder-caret-and-selection-colours]

These take a colour *value*, not a style, so they are named as classes and resolved rather than
applied.

```tsx
<Input
  placeholderColorClassName="accent-muted-foreground"
  selectionColorClassName="accent-info"
/>
```

<Callout type="warn" title="They must be accent-* utilities">
`accent-muted-foreground`, never `text-muted-foreground`. Uniwind reads only `accentColor` off the
compiled class, so anything else resolves to nothing: it warns once in development and leaves the
prop undefined, which renders as the platform default rather than as an error.
</Callout>

## API Reference [#api-reference]

### Input [#input]

Extends React Native's `TextInputProps`. `placeholderTextColorClassName` is withheld in favour of
`placeholderColorClassName`, which is the name the rest of the library uses.

<TypeTable
  type={{
    variant: { type: '"primary" | "secondary"', default: '"primary"' },
    size: { type: '"sm" | "md" | "lg"', default: '"md"' },
    isInvalid: { type: "boolean", description: "Turns the border destructive. Read from an enclosing `Field` when unset." },
    isDisabled: { type: "boolean" },
    placeholderColorClassName: {
      type: "string",
      description: "A class for the placeholder's colour. React Native takes a colour value here, not a style, so it is resolved rather than applied.",
    },
    selectionColorClassName: { type: "string", description: "A class for the caret and selection colour." },
    className: { type: "string" },
    ref: { type: "Ref<TextInputInstance>" },
  }}
/>

### Input.Group [#inputgroup]

Puts a prefix or a suffix inside the input's own border, and publishes the shared axes so the
input inside does not restate them.

<TypeTable
  type={{
    variant: { type: '"primary" | "secondary"' },
    size: { type: '"sm" | "md" | "lg"' },
    isInvalid: { type: "boolean" },
    isDisabled: { type: "boolean" },
    className: { type: "string" },
    children: { type: "ReactNode" },
  }}
/>

### Input.Group.Prefix / Input.Group.Suffix [#inputgroupprefix--inputgroupsuffix]

Content drawn inside the group's border, before or after the field. An `Icon` inside one inherits
the input's icon size and a muted foreground.

<TypeTable
  type={{
    isDecorative: {
      type: "boolean",
      description: "Hide from screen readers and let touches through to the field. Defaults to true when every child is bare text or an `Icon`.",
    },
    className: { type: "string" },
    children: { type: "ReactNode" },
  }}
/>

### Input.Group.Button [#inputgroupbutton]

Takes every `Button` prop except `size` and `isDisabled`, which come from the group.

<TypeTable
  type={{
    variant: { type: '"ghost" | "secondary"', default: '"ghost"' },
    accessibilityLabel: { type: "string", description: "Required for an icon-only button." },
    onPress: { type: "() => void" },
    className: { type: "string" },
    children: { type: "ReactNode" },
  }}
/>

### Input.Group.Separator [#inputgroupseparator]

<TypeTable type={{ className: { type: "string" } }} />

### Input.Group.Block [#inputgroupblock]

<TypeTable
  type={{
    position: { type: '"start" | "end"', description: "Above the field's row, or below it.", required: true },
    className: { type: "string" },
    children: { type: "ReactNode" },
  }}
/>
