Skip to content

Commit 1f6758c

Browse files
epicfaaceedi9999
authored andcommitted
Pass registry to ArrayFieldTemplate (rjsf-team#1317)
* fix: pass registry to ArrayFieldTemplate * test: add test
1 parent 7ed717a commit 1f6758c

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

src/components/fields/ArrayField.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ class ArrayField extends Component {
406406
formContext,
407407
formData,
408408
rawErrors,
409+
registry,
409410
};
410411

411412
// Check if a custom render function was passed in

test/ArrayFieldTemplate_test.js

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { PureComponent } from "react";
2-
32
import { expect } from "chai";
43
import { createFormComponent, createSandbox } from "./test_utils";
54

@@ -39,31 +38,6 @@ describe("ArrayFieldTemplate", () => {
3938
);
4039
}
4140

42-
describe("Stateful ArrayFieldTemplate", () => {
43-
class ArrayFieldTemplate extends PureComponent {
44-
render() {
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-
);
52-
}
53-
}
54-
55-
it("should render a stateful custom component", () => {
56-
const { node } = createFormComponent({
57-
schema: { type: "array", items: { type: "string" } },
58-
formData,
59-
ArrayFieldTemplate,
60-
});
61-
expect(
62-
node.querySelectorAll(".field-array .field-content div")
63-
).to.have.length.of(3);
64-
});
65-
});
66-
6741
describe("not fixed items", () => {
6842
const schema = {
6943
type: "array",
@@ -176,4 +150,45 @@ describe("ArrayFieldTemplate", () => {
176150
});
177151
});
178152
});
153+
154+
describe("Stateful ArrayFieldTemplate", () => {
155+
class ArrayFieldTemplate extends PureComponent {
156+
render() {
157+
return (
158+
<div className="field-content">
159+
{this.props.items.map((item, i) => (
160+
<div key={i}>item.children</div>
161+
))}
162+
</div>
163+
);
164+
}
165+
}
166+
167+
it("should render a stateful custom component", () => {
168+
const { node } = createFormComponent({
169+
schema: { type: "array", items: { type: "string" } },
170+
formData,
171+
ArrayFieldTemplate,
172+
});
173+
expect(
174+
node.querySelectorAll(".field-array .field-content div")
175+
).to.have.length.of(3);
176+
});
177+
});
178+
179+
describe("pass right props to ArrayFieldTemplate", () => {
180+
it("should pass registry prop", () => {
181+
const ArrayFieldTemplate = ({ registry }) => {
182+
if (!registry) {
183+
throw "Error";
184+
}
185+
return null;
186+
};
187+
createFormComponent({
188+
schema: { type: "array", items: { type: "string" } },
189+
formData,
190+
ArrayFieldTemplate,
191+
});
192+
});
193+
});
179194
});

0 commit comments

Comments
 (0)