Skip to content

Commit 290b60b

Browse files
authored
fix(ui5-daterange-picker): month is not changed when select first dat… (#3255)
Until now, when the user navigates to a month in the future or in the past, and the first date of the range is selected, the picker goes back to the current month. Now this is fixed - on a date click the month stays unchanged. Fixes #3129
1 parent 43dab14 commit 290b60b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/main/src/DateRangePicker.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ class DateRangePicker extends DatePicker {
9292
return this._extractLastTimestamp(this.value);
9393
}
9494

95+
get _tempTimestamp() {
96+
return this._tempValue && this.getFormat().parse(this._tempValue, true).getTime() / 1000;
97+
}
98+
9599
/**
96100
* Required by DatePicker.js
97101
* @override
@@ -105,7 +109,7 @@ class DateRangePicker extends DatePicker {
105109
* @override
106110
*/
107111
get _calendarTimestamp() {
108-
return this._firstDateTimestamp || getTodayUTCTimestamp(this._primaryCalendarType);
112+
return this._tempTimestamp || this._firstDateTimestamp || getTodayUTCTimestamp(this._primaryCalendarType);
109113
}
110114

111115
/**
@@ -165,6 +169,14 @@ class DateRangePicker extends DatePicker {
165169
input.setCaretPosition(caretPos); // Return the caret on the previous position after rendering
166170
}
167171

172+
/**
173+
* @override
174+
*/
175+
onResponsivePopoverAfterClose() {
176+
this._tempValue = ""; // reset _tempValue on popover close
177+
super.onResponsivePopoverAfterClose();
178+
}
179+
168180
/**
169181
* @override
170182
*/
@@ -211,7 +223,6 @@ class DateRangePicker extends DatePicker {
211223

212224
const newValue = this._buildValue(...event.detail.dates); // the value will be normalized so we don't need to order them here
213225
this._updateValueAndFireEvents(newValue, true, ["change", "value-changed"]);
214-
this._tempValue = "";
215226
this._focusInputAfterClose = true;
216227
this.closePicker();
217228
}

packages/main/test/specs/DateRangePicker.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,25 @@ describe("DateRangePicker general interaction", () => {
183183
assert.strictEqual(daterangepicker.shadow$("ui5-input").getProperty("valueState"), "None", "The value state is on none");
184184
});
185185

186+
it("Month is not changed in multiselect mode", () => {
187+
browser.url(`http://localhost:${PORT}/test-resources/pages/DateRangePicker.html`);
188+
const staticAreaItemClassName = browser.getStaticAreaItemClassName("#daterange-picker1");
189+
const daterangepicker = browser.$("#daterange-picker1");
190+
const calendarHeader = browser.$(`.${staticAreaItemClassName}`).shadow$(`ui5-calendar`).shadow$(`ui5-calendar-header`);
191+
const dayPicker = browser.$(`.${staticAreaItemClassName}`).shadow$(`ui5-calendar`).shadow$(`ui5-daypicker`);
192+
const dayOne = dayPicker.shadow$(`.ui5-dp-root`).$(".ui5-dp-content").$$("div > .ui5-dp-item" )[15];
193+
const nextButton = calendarHeader.shadow$(`[data-ui5-cal-header-btn-next]`);
194+
const monthButton = calendarHeader.shadow$(`[data-ui5-cal-header-btn-month]`);
195+
const monthName = monthButton.innerHTML;
196+
197+
daterangepicker.click();
198+
browser.keys("F4");
199+
200+
nextButton.click();
201+
nextButton.click();
202+
dayOne.click();
203+
204+
assert.strictEqual(monthButton.innerHTML, monthName, "The month is not changed after selecting the first date in the future");
205+
});
206+
186207
});

0 commit comments

Comments
 (0)