Skip to content

Commit

Permalink
fix: virtual keyboard on mobile should be based on the allowed keys
Browse files Browse the repository at this point in the history
  • Loading branch information
macci001 committed Dec 19, 2024
1 parent 5494fa2 commit 644fbe5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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);
};

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

0 comments on commit 644fbe5

Please sign in to comment.