From 645b8ea06bf3f0145e6cb897995368edb8116482 Mon Sep 17 00:00:00 2001 From: Peterl561 Date: Fri, 20 Dec 2024 15:31:38 -0800 Subject: [PATCH 1/3] fix(input-otp): form validation hook missing behavior --- packages/components/input-otp/src/use-input-otp.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/input-otp/src/use-input-otp.ts b/packages/components/input-otp/src/use-input-otp.ts index 0206c4565d..70cd41947f 100644 --- a/packages/components/input-otp/src/use-input-otp.ts +++ b/packages/components/input-otp/src/use-input-otp.ts @@ -158,7 +158,7 @@ export function useInputOtp(originalProps: UseInputOtpProps) { }); useFormReset(inputRef, value, setValue); - useFormValidation(props, validationState, inputRef); + useFormValidation({...props, validationBehavior}, validationState, inputRef); const { isInvalid: isAriaInvalid, From 150b9be38f37ad53534acaf89984b66c39ec3316 Mon Sep 17 00:00:00 2001 From: Peterl561 Date: Fri, 20 Dec 2024 15:57:40 -0800 Subject: [PATCH 2/3] test(input-otp): isRequired form test --- .../input-otp/__tests__/input-otp.test.tsx | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/components/input-otp/__tests__/input-otp.test.tsx b/packages/components/input-otp/__tests__/input-otp.test.tsx index c1ad664d05..5aec1cbf41 100644 --- a/packages/components/input-otp/__tests__/input-otp.test.tsx +++ b/packages/components/input-otp/__tests__/input-otp.test.tsx @@ -4,6 +4,7 @@ import * as React from "react"; import {render, renderHook, screen} from "@testing-library/react"; import {Controller, useForm} from "react-hook-form"; import userEvent, {UserEvent} from "@testing-library/user-event"; +import {Form} from "@nextui-org/form"; import {InputOtp} from "../src"; @@ -185,6 +186,45 @@ describe("InputOtp Component", () => { }); }); +describe("Validation", () => { + let user: UserEvent; + + beforeAll(() => { + user = userEvent.setup(); + }); + + it("supports isRequired when validationBehavior=native", async () => { + const {getByTestId} = render( +
+ +