From 42eabc6c402027999267dc2b93db6057600def6f Mon Sep 17 00:00:00 2001 From: Joris W Date: Wed, 20 Oct 2021 17:08:23 +0200 Subject: [PATCH] Pass uiSchema to custom Boolean widget (#2587) * Pass uiSchema to custom Boolean widget * Update packages/core/test/BooleanField_test.js Co-authored-by: Ashwin Ramaswami Co-authored-by: Ashwin Ramaswami --- .../src/components/fields/BooleanField.js | 1 + packages/core/test/BooleanField_test.js | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/packages/core/src/components/fields/BooleanField.js b/packages/core/src/components/fields/BooleanField.js index ccf1fbcd7d..28be31e2d3 100644 --- a/packages/core/src/components/fields/BooleanField.js +++ b/packages/core/src/components/fields/BooleanField.js @@ -54,6 +54,7 @@ function BooleanField(props) { { expect(description.textContent).eql("my description"); }); + it("should pass uiSchema to custom widget", () => { + const CustomCheckboxWidget = ({ uiSchema }) => { + return ( +
+ {uiSchema.custom_field_key["ui:options"].test} +
+ ); + }; + + const { node } = createFormComponent({ + schema: { + type: "boolean", + description: "my description", + }, + widgets: { + CheckboxWidget: CustomCheckboxWidget, + }, + uiSchema: { + custom_field_key: { + "ui:widget": "checkbox", + "ui:options": { + test: "foo", + }, + }, + }, + }); + + expect(node.querySelector("#custom-ui-option-value").textContent).to.eql( + "foo" + ); + }); + it("should render the description using provided description field", () => { const { node } = createFormComponent({ schema: {