Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import NumberField from "./NumberField";
import ObjectField from "./ObjectField";
import StringField from "./StringField";
import UnsupportedField from "./UnsupportedField";
import DescriptionField from "./DescriptionField";

const REQUIRED_FIELD_SYMBOL = "*";
const COMPONENT_TYPES = {
Expand Down Expand Up @@ -73,6 +74,7 @@ function Wrapper({
classNames,
errorSchema,
label,
description,
hidden,
help,
required,
Expand All @@ -95,6 +97,7 @@ function Wrapper({
return (
<div className={classList}>
{displayLabel && label ? getLabel(label, required, id) : null}
{description ? <DescriptionField id={`${id}__description`} description={description} /> : null}
{children}
{isError ? <ErrorList errors={errors} /> : <div/>}
{renderHelp(help)}
Expand All @@ -108,6 +111,7 @@ if (process.env.NODE_ENV !== "production") {
id: PropTypes.string,
classNames: PropTypes.string,
label: PropTypes.string,
description: PropTypes.string,
hidden: PropTypes.bool,
help: PropTypes.oneOfType([
PropTypes.string,
Expand Down Expand Up @@ -156,6 +160,7 @@ function SchemaField(props) {
return (
<Wrapper
label={props.schema.title || schema.title || name}
description={props.schema.description || schema.description}
Copy link
Collaborator

@n1k0 n1k0 Jul 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably favor the resolved schema first, what do you think?

Edit: no scratch that you got that right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a preference, actually. Just kept it consistent with the previous expression that sets the label prop.

errorSchema={errorSchema}
hidden={uiSchema["ui:widget"] === "hidden"}
help={uiSchema["ui:help"]}
Expand Down
43 changes: 43 additions & 0 deletions test/SchemaField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,47 @@ describe("SchemaField", () => {
.to.have.length.of(1);
});
});

describe("description support", () => {
const schema = {
type: "object",
properties: {
foo: {type: "string", description:"A Foo field"},
bar: {type: "string"}
}
};

it("should render description if available from the schema", () => {
Copy link
Collaborator

@n1k0 n1k0 Jul 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: insert blank line above this line

const {node} = createFormComponent({schema});
expect(node.querySelectorAll("div#root_foo__description"))
.to.have.length.of(1);
});

it("should render description if available from a referenced schema", () => {
// Overriding.
const schemaWithReference = {
type: "object",
properties: {
foo: {$ref: "#/definitions/foo"},
bar: {type: "string"}
},
definitions: {
foo: {
type: "string",
description: "A Foo field"
}
}
};
const {node} = createFormComponent({schema: schemaWithReference});
const matches = node.querySelectorAll("div#root_foo__description");
expect(matches).to.have.length.of(1);
expect(matches[0].textContent).to.equal("A Foo field");
});

it("should not render description if not available from schema", () => {
const {node} = createFormComponent({schema});
expect(node.querySelectorAll("div#root_bar__description"))
.to.have.length.of(0);
});
});
});