OTP InputLoading saved progress…

OTP Input

Build a one-time-code input as a single React component: six separate single-character boxes, the kind an app shows after texting you a verification code. The interesting part isn't the boxes — it's the focus choreography. Typing a digit fills a box and jumps to the next; backspace walks back; pasting the whole code fans it out across all six. Managing that focus with refs (not DOM queries) is the skill under test.

Signature

Implement the App component in App.tsx. It receives no props and renders the provided six-box one-time-code field. Keep the digits in React state and the input elements in a useRef array.

Examples

  • Focused on box 0, you type 4 — box 0 shows 4 and focus jumps to box 1. Type 2 — box 1 shows 2, focus moves to box 2.
  • Box 3 is empty and focused; you press Backspace — focus moves to box 2 and box 2 is cleared.
  • You paste 12a34-56 into any box — non-digits are removed, all boxes are replaced from box 0, box 5 takes focus, and the line reads Code: 123456.

Notes

  • Only digits. Ignore letters and symbols; the boxes accept 09 only.
  • Exact focus contract. A digit advances unless it is entered in the last box. Backspace clears a filled box without moving; in an empty box it moves left and clears that box. Boundary focus never wraps.
  • Paste replaces the field. Prevent the native paste, keep at most six digits, and distribute them from box 0 regardless of the box that received the event. If no digits remain, leave the current digits and focus unchanged.
  • Focus lives on refs. Reach the next box through your ref array, not document.querySelector. That is the whole point.
  • Completion and accessibility. Derive completion from digits.join(''): show the code only at length six. Preserve the labelled group, per-box position labels, numeric hints, one-time-code autocomplete hint, and polite completion announcement already in the starter.
  • Styling (dark theme, boxes, focus ring) is already in styles.css; focus on the logic.
WE’RE LISTENING

Help make UIReady better

Found a bug or have an idea? Tell us about it.

Up to 3 files · 5 MiB each · JPG, PNG, WebP, MP4, WebM, MP3, M4A or WAV