From 7350caf01f2df5920449abe534531a756147e5dd Mon Sep 17 00:00:00 2001 From: Beier Luo Date: Mon, 5 Dec 2022 18:08:24 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix=20#9521=20isValidting=20prop?= =?UTF-8?q?erty=20stuck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/useFormState.test.tsx | 51 +++++++++++++++++++++++++++++ src/logic/createFormControl.ts | 1 - 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/__tests__/useFormState.test.tsx b/src/__tests__/useFormState.test.tsx index 026b6c25af9..f1e5543adb0 100644 --- a/src/__tests__/useFormState.test.tsx +++ b/src/__tests__/useFormState.test.tsx @@ -118,6 +118,57 @@ describe('useFormState', () => { expect(count).toEqual(1); }); + it('should update isValidating correctly', async () => { + function Child() { + const { isDirty, isValid, isValidating } = useFormState(); + const enabled = !isValidating && isDirty && isValid; + + return ( + + ); + } + + function App() { + const formFunctions = useForm({ + mode: 'onChange', + }); + const { register } = formFunctions; + + return ( + +
+ + + +
+ ); + } + + render(); + + fireEvent.change(screen.getByRole('textbox'), { + target: { + value: '1', + }, + }); + + await waitFor(() => { + expect(screen.getByRole('button')).not.toBeDisabled(); + }); + + fireEvent.change(screen.getByRole('textbox'), { + target: { + value: '12', + }, + }); + + await waitFor(() => { + expect(screen.getByRole('button')).not.toBeDisabled(); + }); + }); + it('should update formState separately with useFormState', async () => { let count = 0; let testCount = 0; diff --git a/src/logic/createFormControl.ts b/src/logic/createFormControl.ts index 1d2a99ce9fb..ed11b568d76 100644 --- a/src/logic/createFormControl.ts +++ b/src/logic/createFormControl.ts @@ -175,7 +175,6 @@ export function createFormControl< const _updateIsValidating = (value: boolean) => _proxyFormState.isValidating && - value !== _formState.isValidating && _subjects.state.next({ isValidating: value, });