-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new accessible otp input component #2428
Conversation
@damianricobelli is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
A OTP verification input fields #1431 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This is looking spectacular! Might also be worthwhile to have an example of usage with zod and react-hook-form (as do other inputs). |
@shadcn The component is ready to be sent to production. I have added 8 complete examples of how to use it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For compatibility with password managers and native phone keyboards, autoComplete
should be one-time-code
. Unsure how that will affect the rest of your implementation
This is amazing! Thanks @damianricobelli |
Done, thanks |
This is amazing 🔥 @damianricobelli |
shadcn_otp_input.mp4When attempting to use arrow keys to shift focus between input boxes, the input unintentionally gets entered into the first box rather than the currently focused one |
@damianricobelli What are your thoughts on https://input-otp.rodz.dev? It's built as a headless component. (Tagging @guilhermerodz if he's available to help us here. Thanks) |
@shadcn hey, I have reviewed the source code and experience of the component you mention. In my opinion it is excellent, but I think the API built here in this PR (and the code) is simpler to understand and refactor for those people who want to use it and modify the component in case they need a different functionality and make it their own. What I would like to take from the operation of the component you mentioned is:
I think that with those two details the component of this PR is extremely flexible and customizable. What do you think? |
@shadcn I have made a last important commit that improves all the usability issues that are still pending in the PR and issues of the react-otp-input library from which this component is inspired. In addition, an example of how to give custom styles to the component is added demonstrating how to achieve in a very simple way the main example of the library that you mentioned in your comment. Although it does not have animations, the idea is to demonstrate how flexible it is to customize the container and each input of the component. Among the improvements, the problem mentioned by @hm-arora is solved |
hi @shadcn @damianricobelli of course I would love to help building the OTP input for shadcn-ui! I reviewed this PR, however I think this is not the best approach... why:
It would be nice for shadcn-ui to only consume/configure primitives, say import + customize otp-input or any other OTP input library. And then providing this as source code at shadcn-ui docs. This is also nice because it supports updates/versioning of the underlying primitive library itself. also, will be pushing a 1.0 (not beta) version of input-otp today! and then @shadcn everyone let me know your thoughts. @damianricobelli I love the examples you've built!! |
@guilhermerodz thank you very much for your feedback. You are right about the accessibility aspect @shadcn do you prefer to continue with an approach where the otp-input component is used? Or to use the current implementation but adding that important accessibility detail that Guilherme mentions? |
@damianricobelli let's go with @guilhermerodz's otp-input. I think this follows the idea/principle behind the components. (Though we're starting to see a few cases where the underlying components are getting too complex - I'm working on a solution for this) |
@damianricobelli Just a quick thank you before I close this PR. Appreciate your help on kicking this off. Thank you. |
This PR is a preview that adds an accessible component called
OTPInput
based on the react-otp-input that allows to render as many inputs as you want (based on the Input component of shadcn) through anumInputs
prop so that a user can write OTP verification codes in an accessible way.The component allows:
Pending tasks:
Previews
I would appreciate feedback and anything you expect from a component of this type