Skip to content

Commit 35b2593

Browse files
feat(ui5-datepicker): implement min and max date limits (#1040)
1 parent e463d23 commit 35b2593

21 files changed

+1047
-80
lines changed

packages/base/src/delegate/ItemNavigation.js

+66-26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import RenderScheduler from "../RenderScheduler.js";
12
import {
23
isDown,
34
isUp,
@@ -47,37 +48,19 @@ class ItemNavigation extends EventProvider {
4748
return this.verticalNavigationOn;
4849
}
4950

50-
_onKeyPress(event) {
51-
const items = this._getItems();
52-
if (this.currentIndex >= items.length) {
53-
if (this.behavior !== ItemNavigationBehavior.Cyclic) {
54-
if (this.behavior === ItemNavigationBehavior.Paging) {
55-
this.currentIndex = this.currentIndex - items.length;
56-
} else {
57-
this.currentIndex = items.length - 1;
58-
}
59-
this.fireEvent(ItemNavigation.BORDER_REACH, { start: false, end: true, offset: this.currentIndex });
60-
} else {
61-
this.currentIndex = this.currentIndex - items.length;
62-
}
51+
async _onKeyPress(event) {
52+
if (this.currentIndex >= this._getItems().length) {
53+
this.onOverflowBottomEdge();
6354
} else if (this.currentIndex < 0) {
64-
if (this.behavior !== ItemNavigationBehavior.Cyclic) {
65-
if (this.behavior === ItemNavigationBehavior.Paging) {
66-
this.currentIndex = items.length + this.currentIndex - this.rowSize + (this.rowSize - (this._getItems().length % this.rowSize));
67-
} else {
68-
this.currentIndex = 0;
69-
}
70-
this.fireEvent(ItemNavigation.BORDER_REACH, { start: true, end: false, offset: this.currentIndex });
71-
} else {
72-
this.currentIndex = items.length + this.currentIndex;
73-
}
55+
this.onOverflowTopEdge();
7456
}
7557

58+
event.preventDefault();
59+
60+
await RenderScheduler.whenFinished();
61+
7662
this.update();
7763
this.focusCurrent();
78-
79-
// stops browser scrolling with up/down keys
80-
event.preventDefault();
8164
}
8265

8366
onkeydown(event) {
@@ -227,8 +210,65 @@ class ItemNavigation extends EventProvider {
227210
set current(val) {
228211
this.currentIndex = val;
229212
}
213+
214+
onOverflowBottomEdge() {
215+
const items = this._getItems();
216+
const rowIndex = this.currentIndex - items.length;
217+
if (this.behavior === ItemNavigationBehavior.Cyclic) {
218+
return;
219+
}
220+
221+
if (this.behavior === ItemNavigationBehavior.Paging) {
222+
this._handleNextPage();
223+
}
224+
225+
this.fireEvent(ItemNavigation.BORDER_REACH, {
226+
start: false, end: true, offset: this.currentIndex, rowIndex,
227+
});
228+
}
229+
230+
onOverflowTopEdge() {
231+
const items = this._getItems();
232+
const rowIndex = this.currentIndex + this.rowSize;
233+
234+
if (this.behavior === ItemNavigationBehavior.Cyclic) {
235+
this.currentIndex = items.length + this.currentIndex;
236+
return;
237+
}
238+
239+
if (this.behavior === ItemNavigationBehavior.Paging) {
240+
this._handlePrevPage();
241+
}
242+
243+
this.fireEvent(ItemNavigation.BORDER_REACH, {
244+
start: true, end: false, offset: this.currentIndex, rowIndex,
245+
});
246+
}
247+
248+
_handleNextPage() {
249+
this.fireEvent(ItemNavigation.PAGE_BOTTOM);
250+
const items = this._getItems();
251+
252+
if (!this.hasNextPage) {
253+
this.currentIndex = items.length - 1;
254+
} else {
255+
this.currentIndex = 0;
256+
}
257+
}
258+
259+
_handlePrevPage() {
260+
this.fireEvent(ItemNavigation.PAGE_TOP);
261+
262+
if (!this.hasPrevPage) {
263+
this.currentIndex = 0;
264+
} else {
265+
this.currentIndex = 41;
266+
}
267+
}
230268
}
231269

270+
ItemNavigation.PAGE_TOP = "PageTop";
271+
ItemNavigation.PAGE_BOTTOM = "PageBottom";
232272
ItemNavigation.BORDER_REACH = "_borderReach";
233273

234274
export default ItemNavigation;

packages/main/src/Calendar.hbs

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
@ui5-pressNext="{{_header.onPressNext}}"
1010
@ui5-btn1Press="{{_header.onBtn1Press}}"
1111
@ui5-btn2Press="{{_header.onBtn2Press}}"
12+
._isNextButtonDisabled="{{_header._isNextButtonDisabled}}"
13+
._isPrevButtonDisabled="{{_header._isPrevButtonDisabled}}"
1214
></ui5-calendar-header>
1315

1416
<div id="{{_id}}-content">
@@ -19,6 +21,8 @@
1921
.selectedDates="{{_oMonth.selectedDates}}"
2022
._hidden="{{_oMonth._hidden}}"
2123
.primaryCalendarType="{{_oMonth.primaryCalendarType}}"
24+
.minDate="{{_oMonth.minDate}}"
25+
.maxDate="{{_oMonth.maxDate}}"
2226
timestamp="{{_oMonth.timestamp}}"
2327
@ui5-selectionChange="{{_oMonth.onSelectedDatesChange}}"
2428
@ui5-navigate="{{_oMonth.onNavigate}}"
@@ -27,17 +31,23 @@
2731
<ui5-monthpicker
2832
id="{{_id}}-MP"
2933
class="{{classes.monthPicker}}"
34+
format-pattern="{{_oMonth.formatPattern}}"
3035
._hidden="{{_monthPicker._hidden}}"
3136
.primaryCalendarType="{{_oMonth.primaryCalendarType}}"
37+
.minDate="{{_oMonth.minDate}}"
38+
.maxDate="{{_oMonth.maxDate}}"
3239
timestamp="{{_monthPicker.timestamp}}"
3340
@ui5-selectedMonthChange="{{_monthPicker.onSelectedMonthChange}}"
3441
></ui5-monthpicker>
3542

3643
<ui5-yearpicker
3744
id="{{_id}}-YP"
3845
class="{{classes.yearPicker}}"
46+
format-pattern="{{_oMonth.formatPattern}}"
3947
._hidden="{{_yearPicker._hidden}}"
4048
.primaryCalendarType="{{_oMonth.primaryCalendarType}}"
49+
.minDate="{{_oMonth.minDate}}"
50+
.maxDate="{{_oMonth.maxDate}}"
4151
timestamp="{{_yearPicker.timestamp}}"
4252
._selectedYear="{{_yearPicker._selectedYear}}"
4353
@ui5-selectedYearChange="{{_yearPicker.onSelectedYearChange}}"

0 commit comments

Comments
 (0)