Input OTP
One-time code entry split into slots.
Import
Section titled “Import”import { InputOTP, InputOTPSlot } from "@pelagornis/page/components";Example
Section titled “Example”The preview above renders this file. Copy it into src/components/ to start from it.
import { useState } from "react";import { InputOTP, InputOTPSlot, Stack, Text } from "@pelagornis/page/components";
export default function InputOTPDemo() { const [code, setCode] = useState("");
return ( <Stack gap="sizeSmall" align="center"> <InputOTP maxLength={6} value={code} onValueChange={setCode} pattern={/\d/} aria-label="Verification code"> {Array.from({ length: 6 }, (_, index) => ( <InputOTPSlot key={index} index={index} /> ))} </InputOTP> <Text variant="captionMd">Code: {code || "—"}</Text> </Stack> );}Use in MDX
Section titled “Use in MDX”Input OTP is composed from parts that share React state. Children written in MDX are rendered as separate islands, so the parts can’t reach each other. Put the composition in a .tsx file, like the example above, and import that file instead.
---title: Example---
import InputOtpExample from "../../components/InputOtpExample";
<InputOtpExample client:load />client:load hydrates the island on page load. Use client:visible for content far down the page.
Use in Markdoc
Section titled “Use in Markdoc”Markdoc tags render Astro components, and this one needs client state. Wrap the example in an .astro file that hydrates it, then register that file as a tag.
---import InputOtpExample from "../InputOtpExample";---
<InputOtpExample client:load />import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";import starlightMarkdoc from "@astrojs/starlight-markdoc";import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({ extends: [starlightMarkdoc(), pageMarkdoc()], tags: { "input-otp-example": { render: component("./src/components/markdoc/InputOtpExample.astro"), selfClosing: true, }, },});{% input-otp-example /%}Variants
Section titled “Variants”Values the component accepts for each variant prop.
| Prop | Values |
|---|---|
size | sm md lg |
Anatomy
Section titled “Anatomy”Parts of the component and the data-refineui role each one renders.
| Part | Role |
|---|---|
root | input-otp |
slot | input-otp-slot |
Keyboard
Section titled “Keyboard”Keys the component handles when it has focus.
| Key | Action |
|---|---|
| ArrowLeft | previous-trigger |
| ArrowRight | next-trigger |
Reference
Section titled “Reference”- RefineUI · Input OTP for design guidance and token detail.
- Use in MDX and Use in Markdoc for the general rules.