Skip to content

Commit d6b3c1b

Browse files
Raniheath-freenome
Rani
andauthored
fix(@rjsf/core): use name for additional properties (#2878)
* fix(@rjsf/core): use name for additional properties * don't use hasOwnProperty * added changelog Co-authored-by: Heath C <[email protected]>
1 parent 4bd50f1 commit d6b3c1b

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
1515
should change the heading of the (upcoming) version to include a major version bump.
1616
1717
-->
18+
19+
# 5.0.0-beta.8
20+
21+
## @rjsf/core
22+
- When rendering additional properties with title, use the key of the property instead of the title.
23+
1824
# v5.0.0-beta.7
1925

2026
## @rjsf/antd

packages/core/src/components/fields/SchemaField.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
RJSFSchemaDefinition,
1414
UIOptionsType,
1515
ID_KEY,
16+
ADDITIONAL_PROPERTY_FLAG,
1617
} from "@rjsf/utils";
1718
import isObject from "lodash/isObject";
1819
import omit from "lodash/omit";
@@ -199,7 +200,10 @@ function SchemaFieldRender<T, F>(props: FieldProps<T, F>) {
199200
if (wasPropertyKeyModified) {
200201
label = name;
201202
} else {
202-
label = uiOptions.title || props.schema.title || schema.title || name;
203+
label =
204+
ADDITIONAL_PROPERTY_FLAG in schema
205+
? name
206+
: uiOptions.title || props.schema.title || schema.title || name;
203207
}
204208

205209
const description =

packages/core/test/ObjectField_test.js

+51-3
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ describe("ObjectField", () => {
446446
expect(node.querySelectorAll(".field-string")).to.have.length.of(1);
447447
});
448448

449-
it("should apply uiSchema to additionalProperties", () => {
449+
it("uiSchema title should not affect additionalProperties", () => {
450450
const { node } = createFormComponent({
451451
schema,
452452
uiSchema: {
@@ -459,8 +459,56 @@ describe("ObjectField", () => {
459459
},
460460
});
461461
const labels = node.querySelectorAll("label.control-label");
462-
expect(labels[0].textContent).eql("CustomName Key");
463-
expect(labels[1].textContent).eql("CustomName");
462+
expect(labels[0].textContent).eql("property1 Key");
463+
expect(labels[1].textContent).eql("property1");
464+
});
465+
466+
it("uiSchema title should update additionalProperties object title", () => {
467+
const objectSchema = {
468+
type: "object",
469+
properties: {
470+
main: {
471+
type: "object",
472+
properties: {},
473+
additionalProperties: {
474+
type: "object",
475+
title: "propTitle",
476+
properties: {
477+
firstName: {
478+
type: "string",
479+
title: "First name",
480+
},
481+
},
482+
},
483+
},
484+
},
485+
};
486+
487+
const { node } = createFormComponent({
488+
schema: objectSchema,
489+
uiSchema: {
490+
main: {
491+
additionalProperties: {
492+
"ui:title": "CustomName",
493+
},
494+
},
495+
},
496+
formData: {
497+
main: {
498+
property1: {
499+
firstName: "hello",
500+
},
501+
},
502+
},
503+
});
504+
const labels = [...node.querySelectorAll("label.control-label")].map(
505+
(n) => n.textContent
506+
);
507+
expect(labels).to.include("property1 Key");
508+
const objectTitle = node.querySelector(
509+
".form-additional > fieldset > legend"
510+
);
511+
expect(objectTitle.textContent).eql("CustomName");
464512
});
465513

466514
it("should not throw validation errors if additionalProperties is undefined", () => {

0 commit comments

Comments
 (0)