Skip to content

Commit 73a2ea7

Browse files
Regginon1k0
authored andcommitted
Show description for boolean fields (rjsf-team#498)
1 parent 241ace3 commit 73a2ea7

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

playground/samples/widgets.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ module.exports = {
2626
properties: {
2727
default: {
2828
type: "boolean",
29-
title: "checkbox (default)"
29+
title: "checkbox (default)",
30+
description: "This is the checkbox-description"
3031
},
3132
radio: {
3233
type: "boolean",
33-
title: "radio buttons"
34+
title: "radio buttons",
35+
description: "This is the radio-description"
3436
},
3537
select: {
3638
type: "boolean",
37-
title: "select box"
39+
title: "select box",
40+
description: "This is the select-description"
3841
}
3942
}
4043
},

src/components/widgets/CheckboxWidget.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {PropTypes} from "react";
2-
2+
import DescriptionField from "../fields/DescriptionField.js";
33

44
function CheckboxWidget({
55
schema,
@@ -13,6 +13,7 @@ function CheckboxWidget({
1313
}) {
1414
return (
1515
<div className={`checkbox ${disabled ? "disabled" : ""}`}>
16+
{ schema.description && <DescriptionField description={ schema.description }/> }
1617
<label>
1718
<input type="checkbox"
1819
id={id}

test/BooleanField_test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ describe("BooleanField", () => {
4747
.to.have.length.of(1);
4848
});
4949

50+
it("should render a description", () => {
51+
const {node} = createFormComponent({schema: {
52+
type: "boolean",
53+
description: "my description"
54+
}});
55+
56+
const description = node.querySelector(".field-description");
57+
expect(description.textContent).eql("my description");
58+
});
59+
5060
it("should assign a default value", () => {
5161
const {node} = createFormComponent({schema: {
5262
type: "boolean",

0 commit comments

Comments
 (0)