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 8942d81
Show file tree
Hide file tree
Showing 2 changed files with 10 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)
5 changes: 5 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,10 @@ export function useInputOtp(originalProps: UseInputOtpProps) {
[baseDomRef, slots, baseStyles, isDisabled, isInvalid, isRequired, isReadOnly, value, length],
);

const isNumeric = (pattern: string) => {
return pattern === "/^\\d+$/";
};

const getInputOtpProps = useCallback(
(props: Partial<OTPInputProps> = {}) => {
const otpProps: Omit<OTPInputProps, "render" | "children"> & {
Expand All @@ -246,6 +250,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 8942d81

Please sign in to comment.