Skip to content

Commit 63cd759

Browse files
sophstadjacqueswho
andauthored
fix(@rjsf/core): Support ui:orderable and ui:removable (rjsf-team#2797)
* Fix ui:orderable and ui:removable * Add tests, update CHANGELOG * Remove extra bracket in test Co-authored-by: Jacques Nel <jacqueswho@gmail.com>
1 parent b25cb60 commit 63cd759

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ should change the heading of the (upcoming) version to include a major version b
2121

2222
## @rjsf/core
2323
- Feature for ui:submitButtonOptions on the submit button for forms (https://github.com/rjsf-team/react-jsonschema-form/pull/2640)
24+
- Fix `ui:orderable` and `ui:removable` in arrays (#2797)
2425

2526
## Dev / docs / playground
2627
- Enable ui options in playground, to demonstrate submit button options (https://github.com/rjsf-team/react-jsonschema-form/pull/2640)
@@ -44,7 +45,7 @@ should change the heading of the (upcoming) version to include a major version b
4445
## @rjsf/fluent-ui
4546
- SubmitButton widget to use new ui:submitButtonOptions on the submit button for forms (https://github.com/rjsf-team/react-jsonschema-form/pull/2640)
4647

47-
# v4.1.1 (upcoming)
48+
# v4.1.1
4849

4950
## @rjsf/material-ui
5051
- Fix bloated bundle size by individually requiring all MUI components (#2754)

packages/core/src/components/fields/ArrayField.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,11 +803,7 @@ class ArrayField extends Component {
803803
const {
804804
fields: { SchemaField },
805805
} = registry;
806-
const { orderable, removable } = {
807-
orderable: true,
808-
removable: true,
809-
...uiSchema["ui:options"],
810-
};
806+
const { orderable = true, removable = true } = getUiOptions(uiSchema);
811807
const has = {
812808
moveUp: orderable && canMoveUp,
813809
moveDown: orderable && canMoveDown,

packages/core/test/ArrayField_test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,19 @@ describe("ArrayField", () => {
710710
expect(moveDownBtns).to.be.null;
711711
});
712712

713+
it("should not show move up/down buttons if ui:orderable is false", () => {
714+
const { node } = createFormComponent({
715+
schema,
716+
formData: ["foo", "bar"],
717+
uiSchema: { "ui:orderable": false },
718+
});
719+
const moveUpBtns = node.querySelector(".array-item-move-up");
720+
const moveDownBtns = node.querySelector(".array-item-move-down");
721+
722+
expect(moveUpBtns).to.be.null;
723+
expect(moveDownBtns).to.be.null;
724+
});
725+
713726
it("should remove a field from the list", () => {
714727
const { node } = createFormComponent({
715728
schema,
@@ -772,6 +785,17 @@ describe("ArrayField", () => {
772785
expect(dropBtn).to.be.null;
773786
});
774787

788+
it("should not show remove button if ui:removable is false", () => {
789+
const { node } = createFormComponent({
790+
schema,
791+
formData: ["foo", "bar"],
792+
uiSchema: { "ui:removable": false },
793+
});
794+
const dropBtn = node.querySelector(".array-item-remove");
795+
796+
expect(dropBtn).to.be.null;
797+
});
798+
775799
it("should force revalidation when a field is removed", () => {
776800
// refs #195
777801
const { node } = createFormComponent({

0 commit comments

Comments
 (0)