diff --git a/packages/uniforms-patternfly/src/DateField.tsx b/packages/uniforms-patternfly/src/DateField.tsx index 795e3bf6046..c7dfd6c86ee 100644 --- a/packages/uniforms-patternfly/src/DateField.tsx +++ b/packages/uniforms-patternfly/src/DateField.tsx @@ -24,13 +24,13 @@ import { TextInput, TextInputProps } from "@patternfly/react-core/dist/js/compon import wrapField from "./wrapField"; export type DateFieldProps = FieldProps< - string, + Date, TextInputProps, { inputRef?: React.RefObject; labelProps?: object; - max?: string; - min?: string; + max?: Date; + min?: Date; type?: "date" | "datetime-local"; } >; @@ -54,16 +54,16 @@ const dateParse = (value: string, onChange: DateFieldProps["onChange"]) => { if (splitedValue.length > 1) { // A year can't be bigger than 9999; splitedValue[0] = parseInt(splitedValue[0]) > 9999 ? "9999" : splitedValue[0]; - onChange(new DateConstructor(`${splitedValue.join("-")}Z`).toISOString()); + onChange(new DateConstructor(`${splitedValue.join("-")}Z`)); return; } onChange(undefined); } else { const date = new DateConstructor(`${value}Z`); if (date.getFullYear() < 10000) { - onChange(date.toISOString()); + onChange(date); } else { - onChange(date.toISOString()); + onChange(date); } } }; diff --git a/packages/uniforms-patternfly/tests/DateField.test.tsx b/packages/uniforms-patternfly/tests/DateField.test.tsx index ab6a5c2fd99..3655f390c01 100644 --- a/packages/uniforms-patternfly/tests/DateField.test.tsx +++ b/packages/uniforms-patternfly/tests/DateField.test.tsx @@ -98,7 +98,7 @@ test(" - renders a input which correctly reacts on change", () => { const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "2000-04-04T10:20" } }); - expect(onChange).toHaveBeenLastCalledWith("x", "2000-04-04T10:20:00.000Z"); + expect(onChange).toHaveBeenLastCalledWith("x", new Date("2000-04-04T10:20:00.000Z")); }); test(" - renders a input which correctly reacts on change (empty value)", () => { @@ -106,7 +106,7 @@ test(" - renders a input which correctly reacts on change (empty valu render( usingUniformsContext( - , + , { x: { type: "string" } }, { onChange } ) @@ -145,16 +145,16 @@ test(" - renders a input which correctly reacts on change (valid)", ( render( usingUniformsContext( - , + , { x: { type: "string" } }, { onChange } ) ); const input = screen.getByTestId("date-field") as HTMLInputElement; - fireEvent.change(input, { target: { value: `2000-04-04T10:30` } }); + fireEvent.change(input, { target: { value: "2000-04-04T10:30" } }); - expect(onChange).toHaveBeenLastCalledWith("x", `2000-04-04T10:30:00.000Z`); + expect(onChange).toHaveBeenLastCalledWith("x", new Date("2000-04-04T10:30:00.000Z")); }); test(" - renders a input which correctly reacts on change (year bigger than 9999)", () => { @@ -165,14 +165,17 @@ test(" - renders a input which correctly reacts on change (year bigge const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "121212-12-12T12:12" } }); - expect(onChange).toHaveBeenLastCalledWith("x", "9999-12-12T12:12:00.000Z"); + expect(onChange).toHaveBeenLastCalledWith("x", new Date("9999-12-12T12:12:00.000Z")); }); test(" - test max property - valid", () => { render( - usingUniformsContext(, { - x: { type: "string" }, - }) + usingUniformsContext( + , + { + x: { type: "string" }, + } + ) ); expect(screen.queryByTestId("Should be before")).toBeNull(); @@ -180,9 +183,12 @@ test(" - test max property - valid", () => { test(" - test max property - invalid", () => { render( - usingUniformsContext(, { - x: { type: "string" }, - }) + usingUniformsContext( + , + { + x: { type: "string" }, + } + ) ); expect(screen.getByText(`Should be before 1999-01-01T00:00:00.000Z`)).toBeInTheDocument(); @@ -190,9 +196,12 @@ test(" - test max property - invalid", () => { test(" - test min property - valid", () => { render( - usingUniformsContext(, { - x: { type: "string" }, - }) + usingUniformsContext( + , + { + x: { type: "string" }, + } + ) ); expect(screen.queryByTestId("Should be after")).toBeNull(); @@ -200,9 +209,12 @@ test(" - test min property - valid", () => { test(" - test min property - invalid", () => { render( - usingUniformsContext(, { - x: { type: "string" }, - }) + usingUniformsContext( + , + { + x: { type: "string" }, + } + ) ); expect(screen.getByText(`Should be after 1999-01-01T00:00:00.000Z`)).toBeInTheDocument();