

<Demo name="otp-field/demos/basic" />

## Installation [#installation]

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/otp-field
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/otp-field
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/otp-field
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun x shadcn@latest add @dotui/otp-field
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Usage [#usage]

Use `OTPField` with `Group` and the existing `Input` component to compose passcode slots.

```tsx
import { OTPField } from '@/components/ui/otp-field'
import { Label } from '@/components/ui/field'
import { Group } from '@/components/ui/group'
import { Input } from '@/components/ui/input'
```

```tsx
<OTPField length={6}>
  <Label>Verification code</Label>
  <Group>
    <Input />
    <Input aria-label="Digit 2" />
    <Input aria-label="Digit 3" />
    <Input aria-label="Digit 4" />
    <Input aria-label="Digit 5" />
    <Input aria-label="Digit 6" />
  </Group>
</OTPField>
```

## Examples [#examples]

<Examples>
  <Example name="otp-field/demos/basic" />

  <Example name="otp-field/demos/separator" />

  <Example name="otp-field/demos/controlled" />

  <Example name="otp-field/demos/disabled" />

  <Example name="otp-field/demos/error-message" />

  <Example name="otp-field/demos/four-digits" />

  <Example name="otp-field/demos/alphanumeric" />

  <Example name="otp-field/demos/form" />
</Examples>

## API Reference [#api-reference]

### OTPField [#otpfield]

<Reference name="otp-field" />

### OTPFieldSeparator [#otpfieldseparator]

<Reference name="otp-field-separator" />
