Skip to content

Commit

Permalink
fix(ui5-calendar): keyboard navigation in the picker grid now works p…
Browse files Browse the repository at this point in the history
…roperly (#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.
  • Loading branch information
unazko authored Dec 3, 2020
1 parent 0c9b8c5 commit 371d12d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/main/src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,15 @@ class Calendar extends UI5Element {

_handleSelectedDatesChange(event) {
const selectedDates = event.detail.dates;
this.timestamp = selectedDates[selectedDates.length - 1];

// Deselecting a date in multiple selection type
if (this.selection === CalendarSelection.Multiple && this.selectedDates.length > selectedDates.length) {
const deselectedDates = this.selectedDates.filter(timestamp => !selectedDates.includes(timestamp));
this.timestamp = deselectedDates[0];
} else {
this.timestamp = selectedDates[selectedDates.length - 1];
}

this.selectedDates = [...selectedDates];
this.fireEvent("selected-dates-change", { dates: selectedDates });
}
Expand Down
19 changes: 19 additions & 0 deletions packages/main/test/specs/Calendar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ describe("Calendar general interaction", () => {
assert.deepEqual(selectedDates, [971136000, 971222400, 971308800], "Change event is fired with proper data");
});

it("Keyboard navigation works properly, when calendar selection type is set to 'Multiple'", () => {
const toggleButton = browser.$("#weekNumbersButton");
const calendar = browser.$("#calendar1");
calendar.setAttribute("selection", "Multiple");
calendar.setAttribute("timestamp", new Date(Date.UTC(2000, 9, 10, 0, 0, 0)).valueOf() / 1000);

toggleButton.click();
toggleButton.click();
browser.keys("Tab");
// Select the focused date
browser.keys("Space");

// Deselect the focused date
browser.keys("Space");
browser.keys("ArrowRight");

assert.ok(calendar.shadow$("ui5-daypicker").shadow$(`[data-sap-timestamp="971222400"]`).isFocusedDeep(), "Focus is properly set");
});

it("Calendar with 'Range' selection type", () => {
const calendar = browser.$("#calendar1");
calendar.setAttribute("timestamp", new Date(Date.UTC(2000, 9, 10, 0, 0, 0)).valueOf() / 1000);
Expand Down

0 comments on commit 371d12d

Please sign in to comment.