Skip to content

Commit

Permalink
SchemaField: Only use nullish coalescing with uiOptions when computin…
Browse files Browse the repository at this point in the history
…g readonly (#4238)

fixes #4236
  • Loading branch information
nickgros committed Jul 2, 2024
1 parent d08cf99 commit 3fc9eba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
21 changes: 10 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ should change the heading of the (upcoming) version to include a major version b
-->

# 5.18.7
# 5.18.6

## @rjsf/antd

- Fix disabled property of options in CheckboxesWidget and RadioWidget ([#4216](https://github.com/rjsf-team/react-jsonschema-form/pull/4216))

## @rjsf/core

- Fixed `omitExtraData` not working in `onSubmit` and `validateForm`; fixing [#4187](https://github.com/rjsf-team/react-jsonschema-form/issues/4187), [#4165](https://github.com/rjsf-team/react-jsonschema-form/issues/4165) and [#4109](https://github.com/rjsf-team/react-jsonschema-form/issues/4109)
- Fixed case where `readOnly` from a JSON Schema was not applied in SchemaField ([#4236](https://github.com/rjsf-team/react-jsonschema-form/issues/4236))

## @rjsf/utils

Expand All @@ -30,16 +39,6 @@ should change the heading of the (upcoming) version to include a major version b

- Fix IdSchema and PathSchema types ([#4196](https://github.com/rjsf-team/react-jsonschema-form/pull/4196))

# 5.18.6

## @rjsf/antd

- Fix disabled property of options in CheckboxesWidget and RadioWidget ([#4216](https://github.com/rjsf-team/react-jsonschema-form/pull/4216))

## @rjsf/core

- Fixed `omitExtraData` not working in `onSubmit` and `validateForm`; fixing [#4187](https://github.com/rjsf-team/react-jsonschema-form/issues/4187), [#4165](https://github.com/rjsf-team/react-jsonschema-form/issues/4165) and [#4109](https://github.com/rjsf-team/react-jsonschema-form/issues/4109)

# 5.18.5

## @rjsf/antd
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/fields/SchemaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e

const FieldComponent = getFieldComponent<T, S, F>(schema, uiOptions, idSchema, registry);
const disabled = Boolean(uiOptions.disabled ?? props.disabled);
const readonly = Boolean(uiOptions.readonly ?? props.readonly ?? props.schema.readOnly ?? schema.readOnly);
const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
const uiSchemaHideError = uiOptions.hideError;
// Set hideError to the value provided in the uiSchema, otherwise stick with the prop to propagate to children
const hideError = uiSchemaHideError === undefined ? props.hideError : Boolean(uiSchemaHideError);
Expand Down
19 changes: 19 additions & 0 deletions packages/core/test/SchemaField.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,23 @@ describe('SchemaField', () => {
expect(textContent).to.contains(descText);
});
});

describe('readOnly', () => {
const schema = {
type: 'object',
properties: {
foo: { type: 'boolean', readOnly: true },
},
};

it('should be readonly if prescribed by the schema', () => {
const { node } = createFormComponent({
schema,
});

const { disabled } = node.querySelector('input');

expect(disabled).to.eq(true);
});
});
});

0 comments on commit 3fc9eba

Please sign in to comment.