Skip to content

Commit

Permalink
🐞 #11106 fix disabled prop not update dirty formState (#11143)
Browse files Browse the repository at this point in the history
* 🐞 #11106  fix disabled prop not update dirty formState

* update test case

* update to max 10kb
  • Loading branch information
bluebill1049 committed Nov 5, 2023
1 parent 32f632a commit 30e5c42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"files": [
{
"path": "./dist/index.cjs.js",
"maxSize": "9.8 kB"
"maxSize": "10 kB"
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/useForm/reset.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ describe('reset', () => {
expect(updatedDirtyFields).toEqual({
firstName: true,
});
expect(updatedDirty).toBeFalsy();
expect(updatedDirty).toBeTruthy();

fireEvent.click(screen.getByRole('button', { name: 'submit' }));

Expand Down Expand Up @@ -849,7 +849,7 @@ describe('reset', () => {
expect(updatedDirtyFields).toEqual({
firstName: true,
});
expect(updatedDirty).toBeFalsy();
expect(updatedDirty).toBeTruthy();

fireEvent.click(screen.getByRole('button', { name: 'submit' }));

Expand Down
11 changes: 11 additions & 0 deletions src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ export function useForm<
[control, props.disabled],
);

React.useEffect(() => {
if (control._proxyFormState.isDirty) {
const isDirty = control._getDirty();
if (isDirty !== formState.isDirty) {
control._subjects.state.next({
isDirty,
});
}
}
}, [control, formState.isDirty]);

React.useEffect(() => {
if (props.values && !deepEqual(props.values, _values.current)) {
control._reset(props.values, control._options.resetOptions);
Expand Down

0 comments on commit 30e5c42

Please sign in to comment.