HextaUI

Input OTP: Invalid

aria-invalid on the root marks every slot. Link the message with aria-describedby.

That code doesn’t match. Check the latest message.

import {
  InputOTP,
  InputOTPGroup,
  InputOTPSlot,
} from "@/components/ui/input-otp"

export function InputOTPInvalid() {
  return (
    <div className="flex max-w-full min-w-0 flex-col items-start gap-2">
      <InputOTP
        length={6}
        defaultValue="111111"
        aria-invalid
        aria-label="Verification code"
        aria-describedby="input-otp-invalid-error"
      >
        <InputOTPGroup>
          <InputOTPSlot />
          <InputOTPSlot />
          <InputOTPSlot />
          <InputOTPSlot />
          <InputOTPSlot />
          <InputOTPSlot />
        </InputOTPGroup>
      </InputOTP>
      <p id="input-otp-invalid-error" className="text-sm text-destructive">
        That code doesn’t match. Check the latest message.
      </p>
    </div>
  )
}

This adds the example as components/examples/input-otp/invalid.tsx, together with the Input OTP component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/input-otp-invalid.json

To add only the component, follow the Input OTP installation.

Props in this example

The Input OTP props this example sets, from the API reference.

PropTypeDefault
lengthRequired. The number of slots; render the same number of InputOTPSlot parts.
number–
defaultValue
string–
aria-invalidMarks every slot invalid.
boolean–

Every prop is in the Input OTP API reference.

See them all, with keyboard support and accessibility notes, on the Input OTP page.