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: virtual keyboard on mobile should be based on the allowed keys #4411

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/cyan-donkeys-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/input-otp": patch
---

Fix virtual keyboard to display the keys based on allowedKeys(#4408)
7 changes: 7 additions & 0 deletions packages/components/input-otp/src/use-input-otp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ export function useInputOtp(originalProps: UseInputOtpProps) {
[baseDomRef, slots, baseStyles, isDisabled, isInvalid, isRequired, isReadOnly, value, length],
);

const isNumeric = (pattern: string) => {
const numericPattern = /(^|\W)[0-9](\W|$)/;

return numericPattern.test(pattern) && !/[^\d\^$\[\]\(\)\*\+\-\.\|]/.test(pattern);
};

Copy link
Member

Choose a reason for hiding this comment

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

@macci001, please move this to the shared-utils package, Also, ensure that the pattern string is validated to confirm it exists (i.e., it should not be null).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the check function to shared-utils.
Also, I think allowedKeys would not be null as we are setting the default value in L110

const getInputOtpProps = useCallback(
(props: Partial<OTPInputProps> = {}) => {
const otpProps: Omit<OTPInputProps, "render" | "children"> & {
Expand All @@ -246,6 +252,7 @@ export function useInputOtp(originalProps: UseInputOtpProps) {
pushPasswordManagerStrategy,
pasteTransformer,
noScriptCSSFallback,
inputMode: isNumeric(allowedKeys) ? "numeric" : "text",
containerClassName: slots.wrapper?.({class: clsx(classNames?.wrapper, containerClassName)}),
...props,
};
Expand Down
Loading