From 2b1141d4c4c50c201de46a23e2a24003682bb6cd Mon Sep 17 00:00:00 2001 From: Sean Perkins Date: Fri, 19 Jan 2024 21:38:19 -0500 Subject: [PATCH] wip: workaround for month/year picker changing value --- core/src/components/datetime/datetime.tsx | 42 ++++++++++++++++------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx index a992a3dbef..4a51c11ee1 100644 --- a/core/src/components/datetime/datetime.tsx +++ b/core/src/components/datetime/datetime.tsx @@ -617,7 +617,11 @@ export class Datetime implements ComponentInterface { }; }; - private setActiveParts = (parts: DatetimeParts, removeDate = false) => { + // TODO - I'm not happy with this change/API. + // But we need to avoid calling confirm() + // Otherwise changing the month/year in the wheel picker + // will update the value of the range selection. + private setActiveParts = (parts: DatetimeParts, removeDate = false, confirmDate = true) => { /** * If the datetime component is in readonly mode, * allow browsing of the calendar without changing @@ -695,7 +699,9 @@ export class Datetime implements ComponentInterface { return; } - this.confirm(); + if (confirmDate) { + this.confirm(); + } }; private get isCalendarPicker() { @@ -1872,7 +1878,7 @@ export class Datetime implements ComponentInterface { return []; } - const { disabled, workingParts } = this; + const { disabled, workingParts, range } = this; const activePart = this.getActivePartsWithFallback() as DatetimeParts; @@ -1896,10 +1902,16 @@ export class Datetime implements ComponentInterface { month: ev.detail.value, }); - this.setActiveParts({ - ...activePart, - month: ev.detail.value, - }); + const shouldUpdateValue = range === true; + + this.setActiveParts( + { + ...activePart, + month: ev.detail.value, + }, + false, + shouldUpdateValue + ); // We can re-attach the scroll listener after // the working parts have been updated. @@ -1926,7 +1938,7 @@ export class Datetime implements ComponentInterface { return []; } - const { disabled, workingParts } = this; + const { disabled, workingParts, range } = this; const activePart = this.getActivePartsWithFallback() as DatetimeParts; @@ -1950,10 +1962,16 @@ export class Datetime implements ComponentInterface { year: ev.detail.value, }); - this.setActiveParts({ - ...activePart, - year: ev.detail.value, - }); + const shouldUpdateValue = range === true; + + this.setActiveParts( + { + ...activePart, + year: ev.detail.value, + }, + false, + shouldUpdateValue + ); // We can re-attach the scroll listener after // the working parts have been updated.