Theme
Install with your agentnpx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-otp-input.json --yes

OTP input

Pro

A row of single-character cells for a one-time code, for a two-step sign-in or confirming an email or a phone, for React and Tailwind CSS. Part of Goop Pro.

Type or paste a code: the last character sends it. A wrong code shows the error, clears the field and keeps the focus there; 246810 signs in (K7QD2M9P in the invite's letters look). Backspace, the arrows, Home and End edit it as one field. Look switches two groups of three, one row of six, or eight letters and digits. The service is a timer that knows one code per look; "Send a new code" sends nothing.

When to use

  • A row of single-character cells for a one-time code, for a two-step sign-in or confirming an email or a phone.
  • Also called: one-time code input, verification code or PIN input.

Installation

Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same OTP input on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing. As a Pro part, its command comes from Goop's server once you sign in, with a one-time link that lasts ten minutes.

Terminal
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-otp-input.json --yes
PROMPT
Add the Goop OTP input to this project. The install steps are at https://goop.so/docs/install.md

Usage

TSX
import { OtpInput } from '@/components/ui/goop/otp-input';
import { useState } from 'react';
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/goop/card';
import { Field } from '@/components/ui/goop/field';
import { FieldInvalid } from '@/components/ui/goop/field-error';
import { Button } from '@/components/ui/goop/button';

function VerifyCode() {
  const [code, setCode] = useState('');
  const [error, setError] = useState('');
  const [field, setField] = useState<HTMLInputElement | null>(null);
  const verify = (entered: string) => {
    if (entered === '424242') return;
    setError('That code is not right. Check the latest message and try again.');
    setCode('');
    field?.focus();
  };
  return (
    <Card asChild variant="outline" className="max-w-pane-md">
      <form
        noValidate
        aria-labelledby="verify-title"
        onSubmit={(event) => {
          event.preventDefault();
          verify(code);
        }}
      >
        <CardHeader>
          <CardTitle asChild>
            <h1 id="verify-title">Check your phone</h1>
          </CardTitle>
        </CardHeader>
        <CardContent className="flex flex-col gap-4">
          <Field label="Verification code" orientation="vertical" className="w-full">
            <FieldInvalid error={error}>
              <OtpInput
                ref={setField}
                name="code"
                groups={[3, 3]}
                value={code}
                onValueChange={(next) => {
                  setCode(next);
                  setError('');
                }}
                onComplete={verify}
              />
            </FieldInvalid>
          </Field>
          <Button type="submit" size="lg" className="w-full">
            Verify
          </Button>
        </CardContent>
      </form>
    </Card>
  );
}
  • Fits: account: field.
  • Also known as: InputOTP, PinInput, OneTimeCode, VerificationCode, DigitInput.
  • Put an OtpInput in a vertical Field and a FieldInvalid on a sign-in or confirmation card; submit from onComplete, and on a wrong code show the error, clear the code and keep the focus in it.
  • height, width, padding, gap, corner, border, background, text, motion: add no class for these.

API reference

Options
OptionTypeWhat it does
length?number = 6How many characters the code has, one cell each.
value?stringThe code, controlled: '' for an empty field.
defaultValue?stringThe code at first, uncontrolled (empty if left out).
onValueChange?(code: string) => voidCalled with the code each time it changes.
onComplete?(code: string) => voidCalled once with the code when its last cell fills.
characters?'digits' | 'letters-digits' = 'digits'"digits" takes 0–9 (a phone's number keypad); "letters-digits" letters, upper-cased, and digits.
groups?readonly number[]The cells in groups, a dash between them ([3, 3]), adding up to length.
lengthLabel?stringThe hidden words heard after the field's name; "6 digits" by default.
onChange?(event: ChangeEvent<HTMLInputElement>) => void
name?string
required?boolean
disabled?boolean
form?string
DefaultsautoComplete = 'one-time-code'
  • State: value (value / defaultValue / onValueChange)
  • data-slot values (to select a part by): otp-input, otp-input-cell, otp-input-control, otp-input-description, otp-input-group, otp-input-indicator, otp-input-separator

Keyboard

KeyWhat it does
0-9 (A-Z with letters-digits)Fill the active cell and move to the next
BackspaceClear the cell before the caret (the last filled)
ArrowLeft ArrowRightMove the caret one cell, never past the next empty one
Home EndMove the caret to the first cell, or the next empty one
EnterSubmit the form

Accessibility

  • The native element answers the keyboard.
  • hover, focus-within: the browser's own (:hover, :focus-within): write nothing

Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:

StateDrawn by
disabledthe prop disabled
invalidthe attribute aria-invalid

Motion

  • The part sets its own motion: add no transition or animation of your own.
  • How the theme moves, and how to move your own parts the same way: Motion.

Notes for AI

Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.

goop.so/themes/trail/components/otp-input.md · the page as Markdown
Theme
Install with your agentnpx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-otp-input.json --yes

Where would you like to start?

Free · now

The Goop plugin

A design system for your AI coding agent, so screen ten matches screen one.

/plugin marketplace add goop-so/skillsthen /plugin install goop@goopCodex, Cursor, ChatGPT, the Claude app and more: Connect Goop
FreePro

The components

Every part live, with its props, its keys and what an agent sees. Whole page and app templates, working with sample data.