From 110349c5a6523a997d90d2a4d119ab731af8effb Mon Sep 17 00:00:00 2001 From: Jani Bolkvadze Date: Tue, 22 Dec 2020 00:29:53 +0100 Subject: [PATCH 1/2] [FSPE-6800] Added support of resetDate to Date Picker wc --- src/custom-elements/docs/docs.json | 13 ++++++++++++- .../src/components/date-picker/date-picker.tsx | 8 ++++++++ src/custom-elements/src/components/date/date.tsx | 14 ++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/custom-elements/docs/docs.json b/src/custom-elements/docs/docs.json index 2613a7782..e01062e9f 100644 --- a/src/custom-elements/docs/docs.json +++ b/src/custom-elements/docs/docs.json @@ -1,5 +1,5 @@ { - "timestamp": "2020-12-17T19:13:01", + "timestamp": "2020-12-21T23:14:09", "compiler": { "name": "@stencil/core", "version": "1.8.9", @@ -911,6 +911,17 @@ "docs": "Gets date", "docsTags": [] }, + { + "name": "resetDate", + "returns": { + "type": "Promise", + "docs": "" + }, + "signature": "resetDate() => Promise", + "parameters": [], + "docs": "Resets date", + "docsTags": [] + }, { "name": "setDate", "returns": { diff --git a/src/custom-elements/src/components/date-picker/date-picker.tsx b/src/custom-elements/src/components/date-picker/date-picker.tsx index ad5940c9a..db38f0c27 100644 --- a/src/custom-elements/src/components/date-picker/date-picker.tsx +++ b/src/custom-elements/src/components/date-picker/date-picker.tsx @@ -155,6 +155,14 @@ export class DatePicker { this.value = date; } + /** + * Resets date + */ + @Method() + async resetDate() { + this.value = null; + } + /** * Gets date */ diff --git a/src/custom-elements/src/components/date/date.tsx b/src/custom-elements/src/components/date/date.tsx index 3c52c5b73..3188cd957 100644 --- a/src/custom-elements/src/components/date/date.tsx +++ b/src/custom-elements/src/components/date/date.tsx @@ -76,11 +76,17 @@ export class Date { @Watch('value') dateChanged(newValue: string, oldValue: string) { if (newValue !== oldValue) { - this._vm.date = newValue ? dayjs(newValue) : null; - if (this._vm.date && !this._vm.date.isValid()) { - throw new Error(`Date ${newValue} has an invalid format. `); + if (newValue) { + this._vm.date = newValue ? dayjs(newValue) : null; + if (this._vm.date && !this._vm.date.isValid()) { + throw new Error(`Date ${newValue} has an invalid format. `); + } + this.viewMonth = this._vm.date; + } else { + this._initCalendarViewModel(); + this.viewMonth = this.value ? this.fromString(this.value) : dayjs(); + this._updateViewMonth(); } - this.viewMonth = this._vm.date; } } From 95a58d6681b85910fb773ddb9adea024a4905dba Mon Sep 17 00:00:00 2001 From: Jani Bolkvadze Date: Tue, 22 Dec 2020 13:18:26 +0100 Subject: [PATCH 2/2] [FSPE-6800] Improved Chi Date value change behavior --- src/custom-elements/docs/docs.json | 2 +- src/custom-elements/src/components/date/date.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/custom-elements/docs/docs.json b/src/custom-elements/docs/docs.json index e01062e9f..b3baa3245 100644 --- a/src/custom-elements/docs/docs.json +++ b/src/custom-elements/docs/docs.json @@ -1,5 +1,5 @@ { - "timestamp": "2020-12-21T23:14:09", + "timestamp": "2020-12-22T12:02:20", "compiler": { "name": "@stencil/core", "version": "1.8.9", diff --git a/src/custom-elements/src/components/date/date.tsx b/src/custom-elements/src/components/date/date.tsx index 3188cd957..43d21c7ab 100644 --- a/src/custom-elements/src/components/date/date.tsx +++ b/src/custom-elements/src/components/date/date.tsx @@ -75,7 +75,7 @@ export class Date { @Watch('value') dateChanged(newValue: string, oldValue: string) { - if (newValue !== oldValue) { + if (newValue !== oldValue && (newValue || oldValue)) { if (newValue) { this._vm.date = newValue ? dayjs(newValue) : null; if (this._vm.date && !this._vm.date.isValid()) {