How would you build OTP component?
retained text
<!-- SC_OFF --><div class="md"><p>Hey all, some time ago I had an interview for a Frontend Engineer role at Stripe and had this question for my coding round:</p> <p>Develop OTP component that has 4 inputs:<br /> - accepts only digits<br /> - when one input is populated => auto-focus to the next<br /> - submit on enter<br /> - should support backspace<br /> - should be accessible</p> <p>I was using React and was trying to make it via 4 separate <code><input></code> elements heavily relying on the built-in HTML validation attributes (to save time, interviewer agreed it was ok). I made it work with auto-focus and everything but still got rejected.</p> <p>Now I'm curious how other would approach such challenge.</p> <p>I will attach an image in the comments for a visual reference.</p> </div><!-- SC_ON -->   submitted by   <a href="https://www.reddit.com/user/truenapalm"> /u/truenapalm </a> <br /> <span><a href="https://www.reddit.com/r/webdev/comments/1tvuwos/how_would_you_build_otp_component/">[link]</a></span>   <span><a href="https://www.reddit.com/r/webdev/comments/1tvuwos/how_would_you_build_otp_component/">[comments]</a></span>
document fetched 2026-06-04 09:48