Skip to content

Commit

Permalink
Pass uiSchema to custom Boolean widget (#2587)
Browse files Browse the repository at this point in the history
* Pass uiSchema to custom Boolean widget

* Update packages/core/test/BooleanField_test.js

Co-authored-by: Ashwin Ramaswami <aramaswamis@gmail.com>

Co-authored-by: Ashwin Ramaswami <aramaswamis@gmail.com>
  • Loading branch information
jorisw and epicfaace committed Oct 20, 2021
1 parent a74099d commit 42eabc6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/src/components/fields/BooleanField.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function BooleanField(props) {
<Widget
options={{ ...options, enumOptions }}
schema={schema}
uiSchema={uiSchema}
id={idSchema && idSchema.$id}
onChange={onChange}
onFocus={onFocus}
Expand Down
32 changes: 32 additions & 0 deletions packages/core/test/BooleanField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,38 @@ describe("BooleanField", () => {
expect(description.textContent).eql("my description");
});

it("should pass uiSchema to custom widget", () => {
const CustomCheckboxWidget = ({ uiSchema }) => {
return (
<div id="custom-ui-option-value">
{uiSchema.custom_field_key["ui:options"].test}
</div>
);
};

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: {
Expand Down

0 comments on commit 42eabc6

Please sign in to comment.