Skip to content

Commit

Permalink
feat: pass maximum and minimum to NumberField (#1341)
Browse files Browse the repository at this point in the history
  • Loading branch information
epicfaace authored Jul 1, 2019
1 parent a8319d7 commit 4ca4e66
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/widgets/BaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ function BaseInput(props) {
inputProps.step = schema.multipleOf;
}

if (typeof schema.minimum !== "undefined") {
inputProps.min = schema.minimum;
}

if (typeof schema.maximum !== "undefined") {
inputProps.max = schema.maximum;
}

const _onChange = ({ target: { value } }) => {
return props.onChange(value === "" ? options.emptyValue : value);
};
Expand Down
22 changes: 22 additions & 0 deletions test/NumberField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,28 @@ describe("NumberField", () => {

expect(node.querySelector("input").step).to.eql("5");
});

it("should use min to represent the minimum keyword", () => {
const { node } = createFormComponent({
schema: {
type: "number",
minimum: 0,
},
});

expect(node.querySelector("input").min).to.eql("0");
});

it("should use max to represent the maximum keyword", () => {
const { node } = createFormComponent({
schema: {
type: "number",
maximum: 100,
},
});

expect(node.querySelector("input").max).to.eql("100");
});
});

describe("SelectWidget", () => {
Expand Down

0 comments on commit 4ca4e66

Please sign in to comment.