Skip to content

Commit ccde545

Browse files
authored
fix(ui5-dynamic-date-range): selection of from value is working when there are previously submitted values (#13470)
When a FROMDATETIME, TODATETIME, or DATETIMERANGE option already had a committed value and the user reopened the picker to change it, the Calendar and DateTimePicker controls were always seeded from this.value (the committed value) instead of this.currentValue (the in-progress value). This caused every interaction inside the picker to snap back to the previously committed value, making it impossible to select a new date. Fix FromDateTimeTemplate.tsx to read the current date from this.currentValue first, falling back to this.value only when no edit is in progress. Fix DateTimeRangeTemplate.tsx with the same approach: prefer this.currentValue when its operator matches the current option, so both the "from" and "to" DateTimePickers reflect the in-progress edit rather than the last committed value.
1 parent 099b325 commit ccde545

3 files changed

Lines changed: 110 additions & 4 deletions

File tree

packages/main/cypress/specs/DynamicDateRange.cy.tsx

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ describe("DynamicDateRange Last/Next Options", () => {
324324
cy.get("@ddr")
325325
.ui5DynamicDateRangeSubmit();
326326

327-
cy.get("@innerInput")
327+
cy.get("@ddr")
328+
.shadow()
329+
.find("[ui5-input]")
330+
.shadow()
331+
.find("input")
328332
.should("have.value", "Last 7 Days");
329333
});
330334

@@ -538,6 +542,72 @@ describe("FromDateTime Option", () => {
538542
cy.get("@input")
539543
.should("contain.value", "From Oct 13, 2025");
540544
});
545+
546+
it("should allow selecting a new date when a previous FromDateTime value exists", () => {
547+
const mockOptions: Array<IDynamicDateRangeOption> = [
548+
new FromDateTime(),
549+
];
550+
cy.get("[ui5-dynamic-date-range]")
551+
.as("ddr")
552+
.ui5DynamicDateRangeOpen()
553+
.ui5DynamicDateRangeSetInput("Oct 1, 2025, 0:30:00 PM")
554+
.ui5DynamicDateRangeSelectOption();
555+
556+
cy.get("@ddr")
557+
.shadow()
558+
.find("[ui5-responsive-popover]")
559+
.as("popover");
560+
561+
cy.get("@popover")
562+
.find("[ui5-calendar]")
563+
.as("calendar");
564+
565+
cy.get("@calendar")
566+
.shadow()
567+
.find("ui5-daypicker")
568+
.shadow()
569+
.find(".ui5-dp-daytext")
570+
.eq(15)
571+
.realClick(); // Select day 13
572+
573+
cy.get("@ddr")
574+
.ui5DynamicDateRangeSubmit();
575+
576+
cy.get("@ddr")
577+
.shadow()
578+
.find("[ui5-input]")
579+
.as("input");
580+
581+
cy.get("@input")
582+
.should("contain.value", "From Oct 13, 2025");
583+
584+
cy.get("@ddr")
585+
.ui5DynamicDateRangeOpen()
586+
.ui5DynamicDateRangeSelectOption();
587+
588+
cy.get("@popover")
589+
.find("[ui5-calendar]")
590+
.as("calendar");
591+
592+
cy.get("@calendar")
593+
.shadow()
594+
.find("ui5-daypicker")
595+
.shadow()
596+
.find(".ui5-dp-daytext")
597+
.eq(16)
598+
.realClick(); // Select day 14
599+
600+
cy.get("@ddr")
601+
.ui5DynamicDateRangeSubmit();
602+
603+
cy.get("@ddr")
604+
.shadow()
605+
.find("[ui5-input]")
606+
.as("input");
607+
608+
cy.get("@input")
609+
.should("contain.value", "From Oct 14, 2025");
610+
});
541611
});
542612

543613
describe("ToDateTime Option", () => {
@@ -749,4 +819,34 @@ describe("DynamicDateRange DateTimeRange Option", () => {
749819
cy.get("@toInput")
750820
.should("have.value", "Feb 26, 2025, 11:59:00 PM");
751821
});
822+
823+
it("should allow picking new dates when a previous DateTimeRange value exists", () => {
824+
// Commit an initial value
825+
cy.get("[ui5-dynamic-date-range]")
826+
.as("ddr")
827+
.ui5DynamicDateRangeOpen()
828+
.ui5DynamicDateRangeSelectOption()
829+
.ui5DynamicDateRangeSetDateTime("from-picker", "Jan 1, 2024, 8:00:00 AM")
830+
.ui5DynamicDateRangeSetDateTime("to-picker", "Jan 2, 2024, 9:00:00 AM")
831+
.ui5DynamicDateRangeSubmit();
832+
833+
cy.get("@ddr")
834+
.shadow()
835+
.find("[ui5-input]")
836+
.should("contain.value", "Jan 1, 2024");
837+
838+
// Reopen and pick different dates — set to-picker first to avoid auto-swap
839+
cy.get("@ddr")
840+
.ui5DynamicDateRangeOpen()
841+
.ui5DynamicDateRangeSelectOption()
842+
.ui5DynamicDateRangeSetDateTime("to-picker", "Mar 6, 2025, 11:00:00 AM")
843+
.ui5DynamicDateRangeSetDateTime("from-picker", "Mar 5, 2025, 10:00:00 AM")
844+
.ui5DynamicDateRangeSubmit();
845+
846+
cy.get("@ddr")
847+
.shadow()
848+
.find("[ui5-input]")
849+
.should("contain.value", "Mar 5, 2025")
850+
.and("contain.value", "Mar 6, 2025");
851+
});
752852
});

packages/main/src/dynamic-date-range-options/DateTimeRangeTemplate.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ export default function DateTimeRangeTemplate(this: DynamicDateRange) {
1010
const currentOperator = this.currentValue?.operator || "DATETIMERANGE";
1111

1212
const getDateFromValue = (index = 0) => {
13-
if (this.value?.operator === currentOperator && this.value.values && this.value.values.length === 2) {
14-
return this.getOption(this.value.operator)?.format(this.value)?.split("-")[index].trim();
13+
const source = this.currentValue?.operator === currentOperator && this.currentValue.values?.length === 2
14+
? this.currentValue
15+
: this.value?.operator === currentOperator && this.value.values?.length === 2
16+
? this.value
17+
: undefined;
18+
19+
if (source) {
20+
return this.getOption(source.operator)?.format(source)?.split("-")[index].trim();
1521
}
1622
return undefined;
1723
};

packages/main/src/dynamic-date-range-options/FromDateTimeTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type FromDateTimeOption from "./FromDateTime.js";
88

99
export default function FromDateTime(this: DynamicDateRange) {
1010
const currentOption = this._currentOption as FromDateTimeOption;
11-
const currentValue = this.value?.values ? this.value.values[0] as Date : undefined;
11+
const currentValue = (this.currentValue?.values ?? this.value?.values)?.[0] as Date | undefined;
1212
return (
1313
<div class="ui5-dynamic-date-range-option-datetime-container">
1414
<div class="ui5-dt-picker-header">

0 commit comments

Comments
 (0)