feat(input-otp): Adding Input OTP component
Closes #2678
📝 Description
PR adds the input-otp componenet
⛳️ Current behavior (updates)
Currently NextUI do not have input-otp component.
🚀 New behavior
-
Default Color
-
Primary Variant (other variant such as Secondary, Success, Warning and Danger follow similar styles)
-
Video represention
input-otp gets added.
💣 Is this a breaking change (Yes/No): no
📝 Additional Information
Summary by CodeRabbit
Summary by CodeRabbit
-
New Features
- Introduced a new
input-otpcomponent for easier one-time password entry. - Automatic focus on the next input field and input length validation enhance usability.
- Integrated with existing themes for a consistent design.
- Customizable properties for appearance, including variants and sizes.
- Introduced a new
-
Tests
- Added unit tests to validate the functionality of the
input-otpcomponent.
- Added unit tests to validate the functionality of the
-
Documentation
- Created a README for the
input-otpcomponent to assist users. - Added comprehensive documentation detailing functionality and customization options.
- Created a README for the
🦋 Changeset detected
Latest commit: 0eab6a129edb1c0d325e1a9a931c355727827d7b
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 3 packages
| Name | Type |
|---|---|
| @nextui-org/input-otp | Minor |
| @nextui-org/theme | Minor |
| @nextui-org/react | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Someone is attempting to deploy a commit to the NextUI Inc Team on Vercel.
A member of the Team first needs to authorize it.
[!NOTE]
Reviews paused
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Walkthrough
This update introduces a new input-otp component to the project, designed for user-friendly entry of one-time passwords (OTPs). It features automatic focus management, input validation, and visual feedback, ensuring a consistent design with existing themes. A suite of unit tests is included to validate the component's functionality and integration with React Hook Form. Additionally, documentation and package configuration are provided for the new component.
Changes
| File(s) | Change Summary |
|---|---|
| .changeset/spotty-flies-jump.md | Added AI-generated summary of changes. |
| packages/components/input-otp/src/input-otp.tsx | Added InputOtp component with focus management and input handling. |
| packages/components/input-otp/src/use-input-otp.ts | Added useInputOtp hook for managing OTP input logic. |
| packages/components/input-otp/stories/input-otp.stories.tsx | Added Storybook configuration for InputOtp component. |
| packages/components/input-otp/package.json | Added package configuration for @nextui-org/input-otp. |
| packages/components/input-otp/README.md | Added documentation for input-otp component. |
| packages/core/theme/src/components/input-otp.ts | Added theming support for input-otp. |
| index.ts | Updated exports for InputOtp and related types. |
| packages/core/theme/src/components/input-otp.ts | Added types and configurations for theming the input-otp component. |
| apps/docs/content/docs/components/input-otp.mdx | Added detailed documentation for the InputOtp component. |
| routes.json | Added new entry for input-otp documentation. |
New files in packages/components/input-otp: allowedKeys.ts, colors.ts, controlled.ts, etc. |
Introduced various utility files for the InputOtp component configurations and usage. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant InputOtp
participant Form
User->>InputOtp: Enter OTP digit
InputOtp->>InputOtp: Validate input
InputOtp->>InputOtp: Focus next input field
InputOtp->>Form: Submit OTP
Form->>Form: Process OTP
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
Introduce input-otp component (#[2678]) |
✅ | |
| Facilitate OTP input for user-friendly access (#[2678]) | ✅ |
Possibly related PRs
- #2038: This PR improves RTL support for input components, which may relate to the
input-otpcomponent's usability in different text directions. - #3106: This PR supplements validation behavior, which could be relevant to the validation features introduced in the
input-otpcomponent. - #3533: This PR addresses synchronization issues between ref values and internal state in input components, which is directly related to the functionality of the
input-otpcomponent. - #3643: This PR ensures that the clear button is not focusable when the input is disabled, which is relevant to the user experience of the
input-otpcomponent. - #3768: This PR fixes the
fullWidthfunctionality in input components, which may impact how theinput-otpcomponent behaves in terms of layout.
Suggested labels
📋 Scope : Docs, 👀 Status: In Review
Suggested reviewers
- wingkwong
- jrgarciadev
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
@coderabbitai full review
Actions performed
Full review triggered.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| nextui-docs-v2 | ❌ Failed (Inspect) | Oct 4, 2024 11:40am | ||
| nextui-storybook-v2 | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 4, 2024 11:40am |
Applied the comments in a168061.
Will add the documentation as well.
Also talking about keyboard left/right navigation, I thought it would be nice UX that whenever a user selects the input-otp component, the segment which needs to be filled will be in focus automatically and they can either add or remove the OTP restricting them not to navigate, given the length of the OTP is usually small. Also most of the UI libraries follows this pattern and the current implementation was done keeping this in mind.
// @wingkwong
Comments are addressed(a1680612a43420a2597ee92f3c627fa2aac052f1) and docs are added(bc5286c076e6088f7a5e4a86136c177651ea10d3) The PR is ready for the next round of review.
@wingkwong, can you please have look at the PR again?
Added the suggestions mentioned in comment in https://github.com/nextui-org/nextui/commit/cab6a940e04a8e4d75fd89529b1dafb6bbc33a5c Just one concern regarding following suggestion:
- in Required, the error message the field is required only shows when there is no input. I think it should also show when the input is not completed (e.g. enter 3 characters in inputOtp with length of 4)
For the above scenario, wouldn't it make sense that input-otp will have
requirederror if nothing is passed. But if the input passed is lesser then the length of the OTP,tooShorterror is passed. Attaching the video-clip below:
https://github.com/user-attachments/assets/4f2ba716-fb15-414a-be4c-4761f0d8213b
I second that. However, the message should be configurable. Also please refer to input component to see validationBehaviour.
The current input-otp component handles the validation behaviour similar to input component. We can configure the error-message by errorMessage prop, so did I miss anything as you mentioned should be configurable in previous comment
if so, then it's all good. Just a reminder only. I haven't checked the code in detail yet.
just an update. we're finalising the design. can you DM me at discord with your email address?
@coderabbitai pause
:white_check_mark: Actions performed
Reviews paused.
UPD: the design is finalised. please refer to the figma I shared to you in discord and update accordingly. thanks.
Hey @macci001 please fix the conflicts