Skip to content
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

Fix #6632 InputOtp keyboard navigation #6638

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions components/lib/inputotp/InputOtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ export const InputOtp = React.memo(
}

default: {
// Prevent non-numeric characters from being entered if integerOnly is true or if the length of the input is greater than the specified length
if ((props?.integerOnly && !((event.code.startsWith('Digit') || event.code.startsWith('Numpad')) && Number(event.key) >= 0 && Number(event.key) <= 9)) || (tokens.join('').length >= props.length && event.code !== 'Delete')) {
//Ignore Enter and Tab pressing and Prevent non-numeric characters from being entered if integerOnly is true or if the length of the input is greater than the specified length
if (
event.code !== 'Tab' &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to put it in separate cases to make it look cleaner

event.code !== 'Enter' &&
((props?.integerOnly && !((event.code.startsWith('Digit') || event.code.startsWith('Numpad')) && Number(event.key) >= 0 && Number(event.key) <= 9)) || (tokens.join('').length >= props.length && event.code !== 'Delete'))
) {
event.preventDefault();
}

Expand Down
Loading