diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f095326f6..1fa369e821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,15 +18,16 @@ should change the heading of the (upcoming) version to include a major version b # 6.0.0-beta.8 -## @rjsf/util - -- Fixed form data propagation with `patternProperties` [#4617](https://github.com/rjsf-team/react-jsonschema-form/pull/4617) - ## @rjsf/chakra-ui - Added `getChakra` to package exports - Restored the `ui:options` customization +## @rjsf/util + +- Fixed form data propagation with `patternProperties` [#4617](https://github.com/rjsf-team/react-jsonschema-form/pull/4617) +- Fixed issue where oneOf schema references could not be modified when defaults were set, fixing [#4580](https://github.com/rjsf-team/react-jsonschema-form/issues/4580). + ## Dev / docs / playground - Updated precompiled schemas documentation in `validation.md` based on v6 changes, addressingg [#4618](https://github.com/rjsf-team/react-jsonschema-form/issues/4618) diff --git a/packages/core/test/Form.test.jsx b/packages/core/test/Form.test.jsx index 5f8709e3dc..96acdc3d98 100644 --- a/packages/core/test/Form.test.jsx +++ b/packages/core/test/Form.test.jsx @@ -1493,6 +1493,60 @@ describeRepeated('Form common', (createFormComponent) => { expect(node.querySelector(secondInputID).value).to.equal('changed!'); }); + it('Should modify oneOf object with references when the defaults are set.', () => { + const schema = { + type: 'object', + $defs: { + protocol: { + type: 'string', + enum: ['fast', 'balanced', 'stringent'], + default: 'fast', + }, + }, + oneOf: [ + { + properties: { + protocol: { + $ref: '#/$defs/protocol', + }, + }, + }, + { + properties: { + something: { + type: 'number', + }, + }, + }, + ], + }; + + const { node, onChange } = createFormComponent({ + schema, + }); + + const protocolInputID = '#root_protocol'; + expect(node.querySelector(protocolInputID).value).to.equal('0'); + + act(() => { + fireEvent.change(node.querySelector(protocolInputID), { + target: { value: '1' }, + }); + }); + + sinon.assert.calledWithMatch( + onChange.lastCall, + { + formData: { + protocol: 'balanced', + }, + schema, + }, + 'root_protocol', + ); + + expect(node.querySelector(protocolInputID).value).to.equal('1'); + }); }); describe('Blur handler', () => { diff --git a/packages/utils/src/schema/getDefaultFormState.ts b/packages/utils/src/schema/getDefaultFormState.ts index 079f11992a..a803648c96 100644 --- a/packages/utils/src/schema/getDefaultFormState.ts +++ b/packages/utils/src/schema/getDefaultFormState.ts @@ -204,7 +204,7 @@ export function computeDefaults