diff --git a/packages/base/src/dates/CalendarDate.js b/packages/base/src/dates/CalendarDate.js index 10655ae9d5ca..8aa4b2efb0ab 100644 --- a/packages/base/src/dates/CalendarDate.js +++ b/packages/base/src/dates/CalendarDate.js @@ -149,7 +149,7 @@ class CalendarDate { function isValidDate(date) { return date && Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date); // eslint-disable-line } - if (!isValidDate()) { + if (!isValidDate(oJSDate)) { throw new Error(`Date parameter must be a JavaScript Date object: [${oJSDate}].`); } return new CalendarDate(oJSDate.getFullYear(), oJSDate.getMonth(), oJSDate.getDate(), sCalendarType); diff --git a/packages/base/src/delegate/ItemNavigation.js b/packages/base/src/delegate/ItemNavigation.js index a08875c8da08..e11f6c64b6fe 100644 --- a/packages/base/src/delegate/ItemNavigation.js +++ b/packages/base/src/delegate/ItemNavigation.js @@ -1,3 +1,4 @@ +import RenderScheduler from "../RenderScheduler.js"; import { isDown, isUp, @@ -47,37 +48,19 @@ class ItemNavigation extends EventProvider { return this.verticalNavigationOn; } - _onKeyPress(event) { - const items = this._getItems(); - if (this.currentIndex >= items.length) { - if (this.behavior !== ItemNavigationBehavior.Cyclic) { - if (this.behavior === ItemNavigationBehavior.Paging) { - this.currentIndex = this.currentIndex - items.length; - } else { - this.currentIndex = items.length - 1; - } - this.fireEvent(ItemNavigation.BORDER_REACH, { start: false, end: true, offset: this.currentIndex }); - } else { - this.currentIndex = this.currentIndex - items.length; - } + async _onKeyPress(event) { + if (this.currentIndex >= this._getItems().length) { + this.onOverflowBottomEdge(); } else if (this.currentIndex < 0) { - if (this.behavior !== ItemNavigationBehavior.Cyclic) { - if (this.behavior === ItemNavigationBehavior.Paging) { - this.currentIndex = items.length + this.currentIndex - this.rowSize + (this.rowSize - (this._getItems().length % this.rowSize)); - } else { - this.currentIndex = 0; - } - this.fireEvent(ItemNavigation.BORDER_REACH, { start: true, end: false, offset: this.currentIndex }); - } else { - this.currentIndex = items.length + this.currentIndex; - } + this.onOverflowTopEdge(); } + event.preventDefault(); + + await RenderScheduler.whenFinished(); + this.update(); this.focusCurrent(); - - // stops browser scrolling with up/down keys - event.preventDefault(); } onkeydown(event) { @@ -227,8 +210,65 @@ class ItemNavigation extends EventProvider { set current(val) { this.currentIndex = val; } + + onOverflowBottomEdge() { + const items = this._getItems(); + const rowIndex = this.currentIndex - items.length; + if (this.behavior === ItemNavigationBehavior.Cyclic) { + return; + } + + if (this.behavior === ItemNavigationBehavior.Paging) { + this._handleNextPage(); + } + + this.fireEvent(ItemNavigation.BORDER_REACH, { + start: false, end: true, offset: this.currentIndex, rowIndex, + }); + } + + onOverflowTopEdge() { + const items = this._getItems(); + const rowIndex = this.currentIndex + this.rowSize; + + if (this.behavior === ItemNavigationBehavior.Cyclic) { + this.currentIndex = items.length + this.currentIndex; + return; + } + + if (this.behavior === ItemNavigationBehavior.Paging) { + this._handlePrevPage(); + } + + this.fireEvent(ItemNavigation.BORDER_REACH, { + start: true, end: false, offset: this.currentIndex, rowIndex, + }); + } + + _handleNextPage() { + this.fireEvent(ItemNavigation.PAGE_BOTTOM); + const items = this._getItems(); + + if (!this.hasNextPage) { + this.currentIndex = items.length - 1; + } else { + this.currentIndex = 0; + } + } + + _handlePrevPage() { + this.fireEvent(ItemNavigation.PAGE_TOP); + + if (!this.hasPrevPage) { + this.currentIndex = 0; + } else { + this.currentIndex = 41; + } + } } +ItemNavigation.PAGE_TOP = "PageTop"; +ItemNavigation.PAGE_BOTTOM = "PageBottom"; ItemNavigation.BORDER_REACH = "_borderReach"; export default ItemNavigation; diff --git a/packages/main/src/Calendar.hbs b/packages/main/src/Calendar.hbs index 779ac8dc8e00..be674a9794cb 100644 --- a/packages/main/src/Calendar.hbs +++ b/packages/main/src/Calendar.hbs @@ -9,6 +9,8 @@ @ui5-pressNext="{{_header.onPressNext}}" @ui5-btn1Press="{{_header.onBtn1Press}}" @ui5-btn2Press="{{_header.onBtn2Press}}" + ._isNextButtonDisabled="{{_header._isNextButtonDisabled}}" + ._isPrevButtonDisabled="{{_header._isPrevButtonDisabled}}" >