From a4d3dfbf0462bc1d4e38439761cc94bdf3818bda Mon Sep 17 00:00:00 2001 From: "Ewe Seong, Yeoh" Date: Thu, 16 Feb 2023 17:41:39 +0800 Subject: [PATCH 1/2] fix: update @sebgroup/frontend-tools to fix date comparison issue --- docs/package.json | 2 +- lib/package.json | 2 +- package-lock.json | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/package.json b/docs/package.json index f6379f1c7..45228a16e 100644 --- a/docs/package.json +++ b/docs/package.json @@ -14,7 +14,7 @@ }, "license": "Apache-2.0", "dependencies": { - "@sebgroup/frontend-tools": "^2.2.1", + "@sebgroup/frontend-tools": "^2.2.2", "browser-typescript-parser": "^2.6.7", "classnames": "^2.3.1", "gatsby": "^4.20.0", diff --git a/lib/package.json b/lib/package.json index 3473ab82e..6d1d62508 100644 --- a/lib/package.json +++ b/lib/package.json @@ -14,7 +14,7 @@ ], "license": "Apache-2.0", "dependencies": { - "@sebgroup/frontend-tools": "^2.2.1", + "@sebgroup/frontend-tools": "^2.2.2", "@types/body-scroll-lock": "^3.1.0", "body-scroll-lock": "^4.0.0-beta.0", "classnames": "^2.3.1", diff --git a/package-lock.json b/package-lock.json index c02fffe2b..61d91d3b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60,7 +60,7 @@ "version": "1.0.0", "license": "Apache-2.0", "dependencies": { - "@sebgroup/frontend-tools": "^2.2.1", + "@sebgroup/frontend-tools": "^2.2.2", "browser-typescript-parser": "^2.6.7", "classnames": "^2.3.1", "gatsby": "^4.20.0", @@ -88,7 +88,7 @@ "version": "1.0.0", "license": "Apache-2.0", "dependencies": { - "@sebgroup/frontend-tools": "^2.2.1", + "@sebgroup/frontend-tools": "^2.2.2", "@types/body-scroll-lock": "^3.1.0", "body-scroll-lock": "^4.0.0-beta.0", "classnames": "^2.3.1", @@ -5770,9 +5770,9 @@ "integrity": "sha512-AkEmzHjRgs0KV1btGwrn+CTEP1uY7zoQGSEmBy6+ZbMlZPquTresdbbh5hvsQ1JYoMzy8hcLz8VPSsw07ZT8yQ==" }, "node_modules/@sebgroup/frontend-tools": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/@sebgroup/frontend-tools/-/frontend-tools-2.2.1.tgz", - "integrity": "sha512-E3A3Reh9ICOkkNXPVrWbrJecc0yvFTq8836wv9/DKAmPFVBIqSO+egxWN+wIbRNO+bbERXbiVzWKY91OdpsC/g==" + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@sebgroup/frontend-tools/-/frontend-tools-2.2.2.tgz", + "integrity": "sha512-1CkN1ZjfGD9UWvWXJEemMvUIbvjDbjqAnUy8nkwtPIB34PvRTQH1QFSQvRZJQjs3Wc06GNi1Kby7+Ux07NnUvg==" }, "node_modules/@semantic-release/changelog": { "version": "6.0.1", @@ -33259,9 +33259,9 @@ "integrity": "sha512-AkEmzHjRgs0KV1btGwrn+CTEP1uY7zoQGSEmBy6+ZbMlZPquTresdbbh5hvsQ1JYoMzy8hcLz8VPSsw07ZT8yQ==" }, "@sebgroup/frontend-tools": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/@sebgroup/frontend-tools/-/frontend-tools-2.2.1.tgz", - "integrity": "sha512-E3A3Reh9ICOkkNXPVrWbrJecc0yvFTq8836wv9/DKAmPFVBIqSO+egxWN+wIbRNO+bbERXbiVzWKY91OdpsC/g==" + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@sebgroup/frontend-tools/-/frontend-tools-2.2.2.tgz", + "integrity": "sha512-1CkN1ZjfGD9UWvWXJEemMvUIbvjDbjqAnUy8nkwtPIB34PvRTQH1QFSQvRZJQjs3Wc06GNi1Kby7+Ux07NnUvg==" }, "@semantic-release/changelog": { "version": "6.0.1", @@ -47023,7 +47023,7 @@ "react-components-docs": { "version": "file:docs", "requires": { - "@sebgroup/frontend-tools": "^2.2.1", + "@sebgroup/frontend-tools": "^2.2.2", "@types/react-helmet": "^6.1.5", "browser-typescript-parser": "^2.6.7", "classnames": "^2.3.1", @@ -47051,7 +47051,7 @@ "@rollup/plugin-commonjs": "^21.0.3", "@rollup/plugin-node-resolve": "^13.1.3", "@rollup/plugin-typescript": "^8.3.1", - "@sebgroup/frontend-tools": "^2.2.1", + "@sebgroup/frontend-tools": "^2.2.2", "@types/body-scroll-lock": "^3.1.0", "@types/jest": "^27.4.1", "babel-jest": "^27.5.1", From 5dbb3460f186bba2a1aa3fe642978ec330fa8c6b Mon Sep 17 00:00:00 2001 From: "Ewe Seong, Yeoh" Date: Thu, 16 Feb 2023 17:56:39 +0800 Subject: [PATCH 2/2] fix: add same day checking to data range validation --- lib/src/Datepicker/Datepicker.test.tsx | 2 ++ lib/src/Datepicker/Datepicker.tsx | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/src/Datepicker/Datepicker.test.tsx b/lib/src/Datepicker/Datepicker.test.tsx index f246d30fc..fef0fcb79 100644 --- a/lib/src/Datepicker/Datepicker.test.tsx +++ b/lib/src/Datepicker/Datepicker.test.tsx @@ -97,8 +97,10 @@ describe("Component: Datepicker", () => { expect(props.onChange).toHaveBeenLastCalledWith(null); changeDate(`${minYear}-01-01`); expect(props.onChange).toHaveBeenCalledTimes(9); + expect(props.onChange).not.toHaveBeenLastCalledWith(null); changeDate(`${maxYear}-01-01`); expect(props.onChange).toHaveBeenCalledTimes(10); + expect(props.onChange).not.toHaveBeenLastCalledWith(null); }); it("should support fallback custom picker", async () => { diff --git a/lib/src/Datepicker/Datepicker.tsx b/lib/src/Datepicker/Datepicker.tsx index bc82c5dda..5443ff9ee 100644 --- a/lib/src/Datepicker/Datepicker.tsx +++ b/lib/src/Datepicker/Datepicker.tsx @@ -1,4 +1,4 @@ -import { isDateAfter } from "@sebgroup/frontend-tools"; +import { isDateAfter, isSameDate } from "@sebgroup/frontend-tools"; import { isDateBefore } from "@sebgroup/frontend-tools/isDateBefore"; import { randomId } from "@sebgroup/frontend-tools/randomId"; import classnames from "classnames"; @@ -456,8 +456,8 @@ function hasModifierKey({ altKey, ctrlKey, metaKey, shiftKey }: React.KeyboardEv } function isDateInRange(d: Date, min: Date, max: Date): boolean { - const isAfterMinDate = !min || !isDateBefore(d, min); - const isBeforeMaxDate = !max || !isDateAfter(d, max); + const isAfterMinDate = !min || isDateAfter(d, min) || isSameDate(d, min); + const isBeforeMaxDate = !max || isDateBefore(d, max) || isSameDate(d, max); return isAfterMinDate && isBeforeMaxDate; }