Skip to content

Commit 66cd1d7

Browse files
authoredDec 16, 2020
fix(ui5-datepicker): keyboard navigation works properly (#2549)
Keyboard navigation now works properly, when ui5-datepicker component popover is opened and there are disabled dates in the corresponding ui5-calendar component due to min/max set.
1 parent a1a3f80 commit 66cd1d7

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed
 

‎packages/main/src/Calendar.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,11 @@ class Calendar extends UI5Element {
631631

632632
async _setDayPickerCurrentIndex(calDate, applyFocus) {
633633
await RenderScheduler.whenFinished();
634-
const currentDate = new CalendarDate(calDate);
635-
const currentDateIndex = this.dayPicker._getVisibleDays(currentDate).findIndex(date => date.valueOf() === currentDate.valueOf());
636-
this.dayPicker._itemNav.currentIndex = currentDateIndex;
634+
const currentDate = new CalendarDate(calDate, this._primaryCalendarType);
635+
const currentIndex = this.dayPicker.focusableDays.findIndex(item => {
636+
return CalendarDate.fromLocalJSDate(new Date(item.timestamp * 1000), this._primaryCalendarType).isSame(currentDate);
637+
});
638+
this.dayPicker._itemNav.currentIndex = currentIndex;
637639
if (applyFocus) {
638640
this.dayPicker._itemNav.focusCurrent();
639641
} else {

‎packages/main/src/DayPicker.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ class DayPicker extends UI5Element {
564564
}
565565

566566
currentTimestamp = calDate.valueOf() / 1000;
567-
const newItemIndex = this._itemNav._getItems().findIndex(item => parseInt(item.timestamp) === currentTimestamp);
567+
const newItemIndex = this.focusableDays.findIndex(item => parseInt(item.timestamp) === currentTimestamp);
568568

569569
this._itemNav.currentIndex = newItemIndex;
570570
this._itemNav.focusCurrent();
@@ -656,7 +656,7 @@ class DayPicker extends UI5Element {
656656
const focusableDays = [];
657657

658658
for (let i = 0; i < this._weeks.length; i++) {
659-
const week = this._weeks[i].slice(1).filter(x => !x.disabled);
659+
const week = this._weeks[i].slice(1).filter(dayItem => !dayItem.disabled);
660660
focusableDays.push(week);
661661
}
662662

@@ -672,7 +672,10 @@ class DayPicker extends UI5Element {
672672
}
673673

674674
_setCurrentItemTabIndex(index) {
675-
this._itemNav._getCurrentItem().setAttribute("tabindex", index.toString());
675+
const currentItem = this._itemNav._getCurrentItem();
676+
if (currentItem) {
677+
currentItem.setAttribute("tabindex", index.toString());
678+
}
676679
}
677680

678681
_modifySelectionAndNotifySubscribers(timestamp) {
@@ -837,7 +840,7 @@ class DayPicker extends UI5Element {
837840
this.fireEvent("navigate", { timestamp });
838841
await RenderScheduler.whenFinished();
839842

840-
const newItemIndex = this._itemNav._getItems().findIndex(item => parseInt(item.timestamp) === timestamp);
843+
const newItemIndex = this.focusableDays.findIndex(item => parseInt(item.timestamp) === timestamp);
841844
this._itemNav.currentIndex = newItemIndex;
842845
this._itemNav.focusCurrent();
843846
}

‎packages/main/src/MonthPicker.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ class MonthPicker extends UI5Element {
237237
}
238238

239239
_setCurrentItemTabIndex(index) {
240-
this._itemNav._getCurrentItem().setAttribute("tabindex", index.toString());
240+
const currentItem = this._itemNav._getCurrentItem();
241+
if (currentItem) {
242+
currentItem.setAttribute("tabindex", index.toString());
243+
}
241244
}
242245

243246
_onmousedown(event) {

‎packages/main/src/YearPicker.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ class YearPicker extends UI5Element {
266266
}
267267

268268
_setCurrentItemTabIndex(index) {
269-
this._itemNav._getCurrentItem().setAttribute("tabindex", index.toString());
269+
const currentItem = this._itemNav._getCurrentItem();
270+
if (currentItem) {
271+
currentItem.setAttribute("tabindex", index.toString());
272+
}
270273
}
271274

272275
_onmousedown(event) {

‎packages/main/test/specs/DatePicker.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -921,4 +921,21 @@ describe("Date Picker Tests", () => {
921921
assert.strictEqual(date.getMonth(), 0, "Correct month value");
922922
assert.strictEqual(date.getFullYear(), 2000, "Correct year value");
923923
});
924+
925+
it("Keyboard navigation works when there are disabled dates in the calendar grid", () => {
926+
datepicker.id = "#dp33";
927+
datepicker.innerInput.click();
928+
browser.keys("Jan 1, 2000");
929+
930+
datepicker.valueHelpIcon.click();
931+
932+
browser.keys("ArrowDown");
933+
934+
assert.ok(datepicker.getDisplayedDay(13).isFocusedDeep(), "Successfully navigated");
935+
936+
browser.keys("Escape");
937+
datepicker.innerInput.click();
938+
browser.keys(["Control", "A"]);
939+
browser.keys("Backspace");
940+
});
924941
});

0 commit comments

Comments
 (0)
Please sign in to comment.