Skip to content

Commit

Permalink
Give ids to array and object fields (#1102)
Browse files Browse the repository at this point in the history
* fix typo in css code

* Give ids to array fields and object fields, give "root" id to the topmost fieldset
  • Loading branch information
epicfaace authored and glasserc committed Jan 10, 2019
1 parent 1a6c867 commit 597a7ba
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/fields/ArrayField.js
Expand Up @@ -103,7 +103,7 @@ function DefaultArrayItem(props) {

function DefaultFixedArrayFieldTemplate(props) {
return (
<fieldset className={props.className}>
<fieldset className={props.className} id={props.idSchema.$id}>
<ArrayFieldTitle
key={`array-field-title-${props.idSchema.$id}`}
TitleField={props.TitleField}
Expand Down Expand Up @@ -139,7 +139,7 @@ function DefaultFixedArrayFieldTemplate(props) {

function DefaultNormalArrayFieldTemplate(props) {
return (
<fieldset className={props.className}>
<fieldset className={props.className} id={props.idSchema.$id}>
<ArrayFieldTitle
key={`array-field-title-${props.idSchema.$id}`}
TitleField={props.TitleField}
Expand Down
2 changes: 1 addition & 1 deletion src/components/fields/ObjectField.js
Expand Up @@ -30,7 +30,7 @@ function DefaultObjectFieldTemplate(props) {

const { TitleField, DescriptionField } = props;
return (
<fieldset>
<fieldset id={props.idSchema.$id}>
{(props.uiSchema["ui:title"] || props.title) && (
<TitleField
id={`${props.idSchema.$id}__title`}
Expand Down
4 changes: 3 additions & 1 deletion test/ArrayField_test.js
Expand Up @@ -41,7 +41,9 @@ describe("ArrayField", () => {
it("should render a fieldset", () => {
const { node } = createFormComponent({ schema });

expect(node.querySelectorAll("fieldset")).to.have.length.of(1);
const fieldset = node.querySelectorAll("fieldset");
expect(fieldset).to.have.length.of(1);
expect(fieldset[0].id).eql("root");
});

it("should render a fieldset legend", () => {
Expand Down
2 changes: 2 additions & 0 deletions test/Form_test.js
Expand Up @@ -127,6 +127,7 @@ describe("Form", () => {
ids.push(input.getAttribute("id"));
}
expect(ids).to.eql(["rjsf_count"]);
expect(node.querySelector("fieldset").id).to.eql("rjsf");
});
});

Expand All @@ -151,6 +152,7 @@ describe("Form", () => {
ids.push(input.getAttribute("id"));
}
expect(ids).to.eql(["rjsf_count"]);
expect(node.querySelector("fieldset").id).to.eql("rjsf");
});

it("should work with oneOf", function() {
Expand Down
4 changes: 3 additions & 1 deletion test/ObjectField_test.js
Expand Up @@ -40,7 +40,9 @@ describe("ObjectField", () => {
it("should render a fieldset", () => {
const { node } = createFormComponent({ schema });

expect(node.querySelectorAll("fieldset")).to.have.length.of(1);
const fieldset = node.querySelectorAll("fieldset");
expect(fieldset).to.have.length.of(1);
expect(fieldset[0].id).eql("root");
});

it("should render a fieldset legend", () => {
Expand Down

0 comments on commit 597a7ba

Please sign in to comment.