Skip to content

An example of moving required styling to classes so can be controlled with css #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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: 2 additions & 3 deletions src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import StringField from "./StringField";
import UnsupportedField from "./UnsupportedField";
import DescriptionField from "./DescriptionField";

const REQUIRED_FIELD_SYMBOL = "*";
const COMPONENT_TYPES = {
"array": ArrayField,
"boolean": BooleanField,
Expand All @@ -40,8 +39,8 @@ function getLabel(label, required, id) {
return null;
}
return (
<label className="control-label" htmlFor={id}>
{required ? label + REQUIRED_FIELD_SYMBOL : label}
<label className={required ? "control-label control-label-required":"control-label"} htmlFor={id}>
{label}
</label>
);
}
Expand Down
5 changes: 1 addition & 4 deletions src/components/fields/TitleField.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React, {PropTypes} from "react";

const REQUIRED_FIELD_SYMBOL = "*";

function TitleField(props) {
const {id, title, required} = props;
const legend = required ? title + REQUIRED_FIELD_SYMBOL : title;
return <legend id={id}>{legend}</legend>;
return <legend id={id} className={required ? "legend-required":""}>{title}</legend>;
}

if (process.env.NODE_ENV !== "production") {
Expand Down
4 changes: 2 additions & 2 deletions test/ObjectField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ describe("ObjectField", () => {
// Required field is <input type="text" required="">
expect(node.querySelector("input[type=text]").getAttribute("required"))
.eql("");
expect(node.querySelector(".field-string label").textContent)
.eql("Foo*");
expect(node.querySelector(".control-label-required").textContent)
.eql("Foo");
});

it("should fill fields with form data", () => {
Expand Down
9 changes: 4 additions & 5 deletions test/TitleField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,22 @@ describe("TitleField", () => {
expect(node.id).to.equal("sample_id");
});

it("should include only title, when field is not required", () => {
it("should not add 'legend-required' class to the title, when field is not required", () => {
const props = {
title: "Field title",
required: false
};
const {node} = createComponent(TitleFieldWrapper, props);

expect(node.textContent).to.equal(props.title);
expect(node.className).not.to.equal("legend-required");
});

it("should add an asterisk to the title, when field is required", () => {
it("should add 'legend-required' class to the title, when field is required", () => {
const props = {
title: "Field title",
required: true
};
const {node} = createComponent(TitleFieldWrapper, props);

expect(node.textContent).to.equal(props.title + "*");
expect(node.className).to.equal("legend-required");
});
});