forked from rjsf-team/react-jsonschema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If you want to change how your FieldTemplate is rendered based on ui:disabled, you currently have to check `uiSchema["ui:disabled"]`, which is unlike the pattern for `readonly` and other known `ui:*` settings.
- Loading branch information
1 parent
fdc5566
commit f4583f9
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from "react"; | ||
|
||
import { expect } from "chai"; | ||
import { createFormComponent, createSandbox } from "./test_utils"; | ||
|
||
describe("FieldTemplate", () => { | ||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = createSandbox(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe("Custom FieldTemplate for disabled property", () => { | ||
function FieldTemplate(props) { | ||
return <div className={props.disabled ? "disabled" : "foo"} />; | ||
} | ||
|
||
it("should render with disabled when ui:disabled is truthy", () => { | ||
const { node } = createFormComponent({ | ||
schema: { type: "string" }, | ||
uiSchema: { "ui:disabled": true }, | ||
FieldTemplate, | ||
}); | ||
expect(node.querySelectorAll(".disabled")).to.have.length.of(1); | ||
}); | ||
|
||
it("should render with disabled when ui:disabled is falsey", () => { | ||
const { node } = createFormComponent({ | ||
schema: { type: "string" }, | ||
uiSchema: { "ui:disabled": false }, | ||
FieldTemplate, | ||
}); | ||
expect(node.querySelectorAll(".disabled")).to.have.length.of(0); | ||
}); | ||
}); | ||
}); |