Skip to content

Commit

Permalink
chore: applying junior's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
macci001 committed Dec 21, 2024
1 parent 644fbe5 commit 6ae4db7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packages/components/input-otp/src/use-input-otp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@nextui-org/system";
import {inputOtp} from "@nextui-org/theme";
import {filterDOMProps, ReactRef, useDOMRef} from "@nextui-org/react-utils";
import {clsx, dataAttr, objectToDeps} from "@nextui-org/shared-utils";
import {clsx, dataAttr, objectToDeps, isPatternNumeric} from "@nextui-org/shared-utils";
import {useCallback, useMemo} from "react";
import {chain, mergeProps, useFormReset} from "@react-aria/utils";
import {AriaTextFieldProps} from "@react-types/textfield";
Expand Down Expand Up @@ -223,12 +223,6 @@ 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 @@ -252,7 +246,7 @@ export function useInputOtp(originalProps: UseInputOtpProps) {
pushPasswordManagerStrategy,
pasteTransformer,
noScriptCSSFallback,
inputMode: isNumeric(allowedKeys) ? "numeric" : "text",
inputMode: isPatternNumeric(allowedKeys) ? "numeric" : "text",
containerClassName: slots.wrapper?.({class: clsx(classNames?.wrapper, containerClassName)}),
...props,
};
Expand Down
1 change: 1 addition & 0 deletions packages/utilities/shared-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from "./numbers";
export * from "./console";
export * from "./types";
export * from "./dates";
export * from "./regex";
5 changes: 5 additions & 0 deletions packages/utilities/shared-utils/src/regex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const isPatternNumeric = (pattern: string) => {
const numericPattern = /(^|\W)[0-9](\W|$)/;

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

0 comments on commit 6ae4db7

Please sign in to comment.