Skip to content

Commit 371d12d

Browse files
authored
fix(ui5-calendar): keyboard navigation in the picker grid now works properly (#2532)
* fix(ui5-calendar): keyboard navigation works properly after date deselection Deselecting a date, when ui5-calendar selection type is "Multiple", now doesn't cause keyboard navigation in the grid to stop working.
1 parent 0c9b8c5 commit 371d12d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/main/src/Calendar.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,15 @@ class Calendar extends UI5Element {
564564

565565
_handleSelectedDatesChange(event) {
566566
const selectedDates = event.detail.dates;
567-
this.timestamp = selectedDates[selectedDates.length - 1];
567+
568+
// Deselecting a date in multiple selection type
569+
if (this.selection === CalendarSelection.Multiple && this.selectedDates.length > selectedDates.length) {
570+
const deselectedDates = this.selectedDates.filter(timestamp => !selectedDates.includes(timestamp));
571+
this.timestamp = deselectedDates[0];
572+
} else {
573+
this.timestamp = selectedDates[selectedDates.length - 1];
574+
}
575+
568576
this.selectedDates = [...selectedDates];
569577
this.fireEvent("selected-dates-change", { dates: selectedDates });
570578
}

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

+19
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,25 @@ describe("Calendar general interaction", () => {
228228
assert.deepEqual(selectedDates, [971136000, 971222400, 971308800], "Change event is fired with proper data");
229229
});
230230

231+
it("Keyboard navigation works properly, when calendar selection type is set to 'Multiple'", () => {
232+
const toggleButton = browser.$("#weekNumbersButton");
233+
const calendar = browser.$("#calendar1");
234+
calendar.setAttribute("selection", "Multiple");
235+
calendar.setAttribute("timestamp", new Date(Date.UTC(2000, 9, 10, 0, 0, 0)).valueOf() / 1000);
236+
237+
toggleButton.click();
238+
toggleButton.click();
239+
browser.keys("Tab");
240+
// Select the focused date
241+
browser.keys("Space");
242+
243+
// Deselect the focused date
244+
browser.keys("Space");
245+
browser.keys("ArrowRight");
246+
247+
assert.ok(calendar.shadow$("ui5-daypicker").shadow$(`[data-sap-timestamp="971222400"]`).isFocusedDeep(), "Focus is properly set");
248+
});
249+
231250
it("Calendar with 'Range' selection type", () => {
232251
const calendar = browser.$("#calendar1");
233252
calendar.setAttribute("timestamp", new Date(Date.UTC(2000, 9, 10, 0, 0, 0)).valueOf() / 1000);

0 commit comments

Comments
 (0)