Skip to content

Commit

Permalink
Merge branch 'main' into get-default-state-test-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
heath-freenome authored Jan 24, 2025
2 parents 71cb9f0 + 978dbea commit 7d6355a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ should change the heading of the (upcoming) version to include a major version b
## @rjsf/utils

- switch `lodash.isEqualWith` to `fast-equals.createCustomEqual` providing `areFunctionsEqual` assuming any functions are equal.
- Fixed issue with fields inside an array can't be set to empty when a default is set, fixing [#4456](https://github.com/rjsf-team/react-jsonschema-form/issues/4456)
- Fixed issue with file accept attribute, fixing [#4404](https://github.com/rjsf-team/react-jsonschema-form/issues/4404).

## @rjsf/mui
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/mergeDefaultsWithFormData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default function mergeDefaultsWithFormData<T = any>(
const overrideOppositeArray = overrideFormDataWithDefaults ? formData : defaultsArray;

const mapped = overrideArray.map((value, idx) => {
if (overrideOppositeArray[idx]) {
// We want to explicitly make sure that the value is NOT undefined since null, 0 and empty space are valid values
if (overrideOppositeArray[idx] !== undefined) {
return mergeDefaultsWithFormData<any>(
defaultsArray[idx],
formData[idx],
Expand Down
32 changes: 32 additions & 0 deletions packages/utils/test/mergeDefaultsWithFormData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,38 @@ describe('mergeDefaultsWithFormData()', () => {
expect(mergeDefaultsWithFormData({}, undefined, undefined, undefined, true)).toEqual(undefined);
});

it('should deeply merge and return formData when formData is undefined and defaultSupercedesUndefined false', () => {
expect(
mergeDefaultsWithFormData(
{
arrayWithDefaults: ['Hello World'],
objectWidthDefaults: {
nestedField: 'Hello World!',
},
stringField: 'Hello World!!',
},
{
arrayWithDefaults: [null],
objectWidthDefaults: {
nestedField: undefined,
},
stringField: undefined,
nonEmptyField: 'Hello World!!!',
},
undefined,
undefined,
true
)
).toEqual({
arrayWithDefaults: [null],
objectWidthDefaults: {
nestedField: undefined,
},
stringField: undefined,
nonEmptyField: 'Hello World!!!',
});
});

it('should return default when formData is undefined and defaultSupercedesUndefined true', () => {
expect(mergeDefaultsWithFormData({}, undefined, undefined, true, true)).toEqual({});
});
Expand Down

0 comments on commit 7d6355a

Please sign in to comment.