Skip to content

Commit

Permalink
Merge pull request #784 from janibolkvadze/FSPE-6800-Add-support-of-r…
Browse files Browse the repository at this point in the history
…eset-method-to-Date-Picker-web-component

[FSPE-6800] Added support of resetDate to Date Picker wc
  • Loading branch information
jllr authored Dec 22, 2020
2 parents 06b1e02 + 95a58d6 commit dc0bfd5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/custom-elements/docs/docs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"timestamp": "2020-12-17T19:13:01",
"timestamp": "2020-12-22T12:02:20",
"compiler": {
"name": "@stencil/core",
"version": "1.8.9",
Expand Down Expand Up @@ -911,6 +911,17 @@
"docs": "Gets date",
"docsTags": []
},
{
"name": "resetDate",
"returns": {
"type": "Promise<void>",
"docs": ""
},
"signature": "resetDate() => Promise<void>",
"parameters": [],
"docs": "Resets date",
"docsTags": []
},
{
"name": "setDate",
"returns": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ export class DatePicker {
this.value = date;
}

/**
* Resets date
*/
@Method()
async resetDate() {
this.value = null;
}

/**
* Gets date
*/
Expand Down
16 changes: 11 additions & 5 deletions src/custom-elements/src/components/date/date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ 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 !== oldValue && (newValue || oldValue)) {
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;
}
}

Expand Down

0 comments on commit dc0bfd5

Please sign in to comment.