Skip to content

Commit a6eff3f

Browse files
SuriGillepicfaace
authored andcommitted
fix: update arrays correctly when changing index (rjsf-team#1485)
1 parent 635df88 commit a6eff3f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/components/fields/ArrayField.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ class ArrayField extends Component {
750750
return {
751751
children: (
752752
<SchemaField
753+
index={index}
753754
schema={itemSchema}
754755
uiSchema={itemUiSchema}
755756
formData={itemData}

test/ArrayField_test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,23 @@ describe("ArrayField", () => {
616616
expect(inputs[0].value).eql("bar");
617617
});
618618

619+
it("should delete item from list and correct indices", () => {
620+
const { node } = createFormComponent({
621+
schema,
622+
formData: ["foo", "bar", "baz"],
623+
});
624+
const deleteBtns = node.querySelectorAll(".array-item-remove");
625+
626+
Simulate.click(deleteBtns[0]);
627+
628+
const inputs = node.querySelectorAll(".field-string input[type=text]");
629+
630+
Simulate.change(inputs[0], { target: { value: "fuzz" } });
631+
expect(inputs).to.have.length.of(2);
632+
expect(inputs[0].value).eql("fuzz");
633+
expect(inputs[1].value).eql("baz");
634+
});
635+
619636
it("should retain row keys/ids of remaining rows when a row is removed", () => {
620637
const { node } = createFormComponent({
621638
schema,

0 commit comments

Comments
 (0)