Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): field ui-options higher priority #4212

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ should change the heading of the (upcoming) version to include a major version b

- Fix case where NumberField would not properly reset the field when using programmatic form reset (#4202)[https://github.com/rjsf-team/react-jsonschema-form/issues/4202]
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
- Fix field disable or readonly property can't cover globalOptions corresponding property (#4212)[https://github.com/rjsf-team/react-jsonschema-form/pull/4212]

## @rfsf/fluent-ui

Expand All @@ -55,7 +56,6 @@ should change the heading of the (upcoming) version to include a major version b

- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers


## @rjsf/validator-ajv6

- Improved performance issues with large schema dependencies and oneOf conditions [#4203](https://github.com/rjsf-team/react-jsonschema-form/issues/4203).
Expand Down Expand Up @@ -95,6 +95,7 @@ should change the heading of the (upcoming) version to include a major version b
# 5.18.0

## @rjsf/antd

- Fix issue where the theme provided by the ConfigProvider under antd v5 wasn't respected thereby rendering the form items unusable under dark themes [#4129](https://github.com/rjsf-team/react-jsonschema-form/issues/4129)

## @rjsf/core
Expand Down Expand Up @@ -133,7 +134,7 @@ should change the heading of the (upcoming) version to include a major version b

## Dev / docs / playground

- [#4080](https://github.com/rjsf-team/react-jsonschema-form/issues/4080) - Moved the `base64` encoder/decoder object to the Playground package.
- [#4080](https://github.com/rjsf-team/react-jsonschema-form/issues/4080) - Moved the `base64` encoder/decoder object to the Playground package.
- Added test configuration and script to the Playground.

# 5.17.0
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ export default class Form<
acceptcharset,
acceptCharset,
noHtml5Validate = false,
disabled = false,
readonly = false,
disabled,
readonly,
formContext,
showErrorList = 'top',
_internalFormWrapper,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/fields/ObjectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
idSchema,
name,
required = false,
disabled = false,
readonly = false,
disabled,
readonly,
hideError,
idPrefix,
idSeparator,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/components/fields/SchemaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
);

const FieldComponent = getFieldComponent<T, S, F>(schema, uiOptions, idSchema, registry);
const disabled = Boolean(props.disabled || uiOptions.disabled);
const readonly = Boolean(props.readonly || uiOptions.readonly || props.schema.readOnly || schema.readOnly);
const disabled = Boolean(uiOptions.disabled ?? props.disabled);
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);
const autofocus = Boolean(props.autofocus || uiOptions.autofocus);
const autofocus = Boolean(uiOptions.autofocus ?? props.autofocus);
if (Object.keys(schema).length === 0) {
return null;
}
Expand Down
38 changes: 32 additions & 6 deletions packages/core/test/uiSchema.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2505,9 +2505,7 @@ describe('uiSchema', () => {
});

describe('ObjectField', () => {
let node;

beforeEach(() => {
it('should mark as readonly an ObjectField', () => {
const schema = {
type: 'object',
properties: {
Expand All @@ -2523,13 +2521,41 @@ describe('uiSchema', () => {
const uiSchema = {};

let rendered = createFormComponent({ schema, uiSchema });
node = rendered.node;
});
const node = rendered.node;

it('should mark as readonly an ObjectField', () => {
const disabled = [].map.call(node.querySelectorAll('[type=text]'), (node) => node.hasAttribute('readonly'));
expect(disabled).eql([true, true]);
});

it('should not mark as readonly even if globalOptions set readonly', () => {
const schema = {
type: 'object',
properties: {
foo: {
type: 'string',
},
bar: {
type: 'string',
},
},
readOnly: true,
};

const uiSchema = {
'ui:globalOptions': {
readonly: true,
},
foo: {
'ui:readonly': false,
},
};

let rendered = createFormComponent({ schema, uiSchema });
const node = rendered.node;

const disabled = [].map.call(node.querySelectorAll('[type=text]'), (node) => node.hasAttribute('readonly'));
expect(disabled).eql([false, true]);
});
});
});

Expand Down
12 changes: 6 additions & 6 deletions packages/utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
/** A boolean value stating if the field should autofocus */
autofocus?: boolean;
/** A boolean value stating if the field is disabled */
disabled: boolean;
disabled?: boolean;
/** A boolean value stating if the field is hiding its errors */
hideError?: boolean;
/** A boolean value stating if the field is read-only */
readonly: boolean;
readonly?: boolean;
/** The required status of this field */
required?: boolean;
/** The unique name of the field, usually derived from the name of the property in the JSONSchema */
Expand Down Expand Up @@ -545,7 +545,7 @@ export type ArrayFieldTemplateItemType<
/** The className string */
className: string;
/** A boolean value stating if the array item is disabled */
disabled: boolean;
disabled?: boolean;
/** A boolean value stating whether new items can be added to the array */
canAdd: boolean;
/** A boolean value stating whether the array item can be copied, assumed false if missing */
Expand All @@ -571,7 +571,7 @@ export type ArrayFieldTemplateItemType<
/** Returns a function that swaps the items at `index` with `newIndex` */
onReorderClick: (index: number, newIndex: number) => (event?: any) => void;
/** A boolean value stating if the array item is read-only */
readonly: boolean;
readonly?: boolean;
/** A stable, unique key for the array item */
key: string;
/** The schema object for this array item */
Expand Down Expand Up @@ -631,9 +631,9 @@ export type ObjectFieldTemplatePropertyType = {
/** A string representing the property name */
name: string;
/** A boolean value stating if the object property is disabled */
disabled: boolean;
disabled?: boolean;
/** A boolean value stating if the property is read-only */
readonly: boolean;
readonly?: boolean;
/** A boolean value stating if the property should be hidden */
hidden: boolean;
};
Expand Down