Skip to content

Commit

Permalink
[@mantine/form] Fix incorrect values handling in form.resetDirty (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrehnstrom authored Jan 18, 2025
1 parent c29a6c6 commit 4edaa61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function useFormStatus<Values extends Record<string, any>>({

const resetDirty: ResetDirty<Values> = useCallback((values) => {
const newSnapshot = values
? { ...values, ...$values.refValues.current }
? { ...$values.refValues.current, ...values }
: $values.refValues.current;
$values.setValuesSnapshot(newSnapshot);
setDirty({});
Expand Down
8 changes: 8 additions & 0 deletions packages/@mantine/form/src/tests/use-form/resetDirty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ function tests(mode: FormMode) {

expect(hook.result.current.isDirty()).toBe(false);
});

it('should handle reseting with new values', () => {
const hook = renderHook(() => useForm({ mode, initialValues: { a: 1, b: 2 } }));
expect(hook.result.current.isDirty()).toBe(false);

act(() => hook.result.current.resetDirty({ a: 2, b: 2 }));
expect(hook.result.current.isDirty()).toBe(true);
});
}

describe('@mantine/form/resetDirty-controlled', () => {
Expand Down

0 comments on commit 4edaa61

Please sign in to comment.