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

feat: pass down indexed title from array field #4002

Merged
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
should change the heading of the (upcoming) version to include a major version bump.

-->
# 5.16.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a point release

Suggested change
# 5.16.1
# 5.15.2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


## @rjsf/core

- Pass indexed title from array into its items, adding enhancement asked in [#3983](https://github.com/rjsf-team/react-jsonschema-form/issues/3983)

# 5.15.1

## @rjsf/core
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/components/fields/ArrayField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
key,
index,
name: name && `${name}-${index}`,
title: title ? `${title}-${index + 1}` : undefined,
canAdd,
canMoveUp: index > 0,
canMoveDown: index < formData.length - 1,
Expand Down Expand Up @@ -759,6 +760,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
key,
index,
name: name && `${name}-${index}`,
title: title ? `${title}-${index + 1}` : undefined,
canAdd,
canRemove: additional,
canMoveUp: index >= itemSchemas.length + 1,
Expand Down Expand Up @@ -799,6 +801,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
key: string;
index: number;
name: string;
title: string | undefined;
canAdd: boolean;
canRemove?: boolean;
canMoveUp: boolean;
Expand Down Expand Up @@ -832,6 +835,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
onFocus,
rawErrors,
totalItems,
title,
} = props;
const { disabled, hideError, idPrefix, idSeparator, readonly, uiSchema, registry, formContext } = this.props;
const {
Expand All @@ -853,6 +857,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
children: (
<ItemSchemaField
name={name}
title={title}
index={index}
schema={itemSchema}
uiSchema={itemUiSchema}
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/components/fields/BooleanField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ function BooleanField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
readonly,
hideError,
autofocus,
title,
onChange,
onFocus,
onBlur,
rawErrors,
} = props;
const { title } = schema;
const { title: schemaTitle } = schema;
const { widgets, formContext, translateString, globalUiOptions } = registry;
const {
widget = 'checkbox',
Expand All @@ -49,7 +50,7 @@ function BooleanField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
const yes = translateString(TranslatableString.YesLabel);
const no = translateString(TranslatableString.NoLabel);
let enumOptions: EnumOptionsType<S>[] | undefined;
const label = uiTitle ?? title ?? name;
const label = uiTitle ?? schemaTitle ?? title ?? name;
if (Array.isArray(schema.oneOf)) {
enumOptions = optionsList<S>({
oneOf: schema.oneOf
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/components/fields/ObjectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
onBlur,
onFocus,
registry,
title,
} = this.props;

const { fields, formContext, schemaUtils, translateString, globalUiOptions } = registry;
Expand All @@ -249,7 +250,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
const { properties: schemaProperties = {} } = schema;

const title = uiOptions.title ?? schema.title ?? name;
const templateTitle = uiOptions.title ?? schema.title ?? title ?? name;
const description = uiOptions.description ?? schema.description;
let orderedProperties: string[];
try {
Expand All @@ -272,7 +273,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo

const templateProps = {
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
title: uiOptions.label === false ? '' : title,
title: uiOptions.label === false ? '' : templateTitle,
description: uiOptions.label === false ? undefined : description,
properties: orderedProperties.map((name) => {
const addedByAdditionalProperties = has(schema, [PROPERTIES_KEY, name, ADDITIONAL_PROPERTY_FLAG]);
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/components/fields/SchemaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
if (wasPropertyKeyModified) {
label = name;
} else {
label = ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || name;
label =
ADDITIONAL_PROPERTY_FLAG in schema
? name
: uiOptions.title || props.schema.title || schema.title || props.title || name;
}

const description = uiOptions.description || props.schema.description || schema.description || '';
Expand Down