Skip to content

Commit b096c99

Browse files
gr8pathikepicfaace
authored andcommitted
rjsf-team#804 - Bug Fix - Empty divs are created (rjsf-team#1218)
* rjsf-team#804 - Bug Fix - Empty divs are created * rjsf-team#804 - Bug Fix - Empty divs are created - Refactoring
1 parent d9bcf1a commit b096c99

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/components/fields/ArrayField.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@ import {
2121

2222
function ArrayFieldTitle({ TitleField, idSchema, title, required }) {
2323
if (!title) {
24-
// See #312: Ensure compatibility with old versions of React.
25-
return <div />;
24+
return null;
2625
}
2726
const id = `${idSchema.$id}__title`;
2827
return <TitleField id={id} title={title} required={required} />;
2928
}
3029

3130
function ArrayFieldDescription({ DescriptionField, idSchema, description }) {
3231
if (!description) {
33-
// See #312: Ensure compatibility with old versions of React.
34-
return <div />;
32+
return null;
3533
}
3634
const id = `${idSchema.$id}__description`;
3735
return <DescriptionField id={id} description={description} />;

src/components/fields/DescriptionField.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import PropTypes from "prop-types";
44
function DescriptionField(props) {
55
const { id, description } = props;
66
if (!description) {
7-
// See #312: Ensure compatibility with old versions of React.
8-
return <div />;
7+
return null;
98
}
109
if (typeof description === "string") {
1110
return (

src/components/fields/SchemaField.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ function getFieldComponent(schema, uiSchema, idSchema, fields) {
6161
function Label(props) {
6262
const { label, required, id } = props;
6363
if (!label) {
64-
// See #312: Ensure compatibility with old versions of React.
65-
return <div />;
64+
return null;
6665
}
6766
return (
6867
<label className="control-label" htmlFor={id}>
@@ -88,8 +87,7 @@ function LabelInput(props) {
8887
function Help(props) {
8988
const { help } = props;
9089
if (!help) {
91-
// See #312: Ensure compatibility with old versions of React.
92-
return <div />;
90+
return null;
9391
}
9492
if (typeof help === "string") {
9593
return <p className="help-block">{help}</p>;
@@ -100,7 +98,7 @@ function Help(props) {
10098
function ErrorList(props) {
10199
const { errors = [] } = props;
102100
if (errors.length === 0) {
103-
return <div />;
101+
return null;
104102
}
105103

106104
return (
@@ -254,10 +252,8 @@ function SchemaFieldRender(props) {
254252
const disabled = Boolean(props.disabled || uiSchema["ui:disabled"]);
255253
const readonly = Boolean(props.readonly || uiSchema["ui:readonly"]);
256254
const autofocus = Boolean(props.autofocus || uiSchema["ui:autofocus"]);
257-
258255
if (Object.keys(schema).length === 0) {
259-
// See #312: Ensure compatibility with old versions of React.
260-
return <div />;
256+
return null;
261257
}
262258

263259
const uiOptions = getUiOptions(uiSchema);

test/ArrayFieldTemplate_test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ describe("ArrayFieldTemplate", () => {
4242
describe("Stateful ArrayFieldTemplate", () => {
4343
class ArrayFieldTemplate extends PureComponent {
4444
render() {
45-
return <div>{this.props.items.map(item => item.element)}</div>;
45+
return (
46+
<div className="field-content">
47+
{this.props.items.map((item, i) => (
48+
<div key={i}>item.children</div>
49+
))}
50+
</div>
51+
);
4652
}
4753
}
4854

@@ -52,8 +58,9 @@ describe("ArrayFieldTemplate", () => {
5258
formData,
5359
ArrayFieldTemplate,
5460
});
55-
56-
expect(node.querySelectorAll(".field-array div")).to.have.length.of(3);
61+
expect(
62+
node.querySelectorAll(".field-array .field-content div")
63+
).to.have.length.of(3);
5764
});
5865
});
5966

test/SchemaField_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe("SchemaField", () => {
108108
receivedProps = props;
109109
}
110110
render() {
111-
return <div />;
111+
return null;
112112
}
113113
},
114114
},

0 commit comments

Comments
 (0)