Skip to content

Commit

Permalink
feat(ui5-calendar): focus the nearest day when today is out of range (#…
Browse files Browse the repository at this point in the history
…6801)

fixes: #6750
  • Loading branch information
tsanislavgatev authored and NHristov-sap committed May 4, 2023
1 parent 38d0b9d commit 85c3673
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/main/src/CalendarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ class CalendarPart extends DateComponentBase {
*/
get _timestamp() {
let timestamp = this.timestamp !== undefined ? this.timestamp : getTodayUTCTimestamp(this._primaryCalendarType);
if (timestamp < this._minTimestamp || timestamp > this._maxTimestamp) {

if (this._maxTimestamp && this._maxTimestamp < timestamp) {
timestamp = this._maxTimestamp;
} else if (this._minTimestamp && this._minTimestamp > timestamp) {
timestamp = this._minTimestamp;
}

return timestamp;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/main/test/pages/Calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
</section>

<section>
<ui5-calendar id="calendar11" min-date="tomorrow"></ui5-calendar>
<ui5-calendar id="calendar12" max-date="yesterday"></ui5-calendar>
<ui5-calendar id="calendar3" min-date="1/7/2020" max-date="21/10/2020" format-pattern="dd/MM/yyyy"></ui5-calendar>
</section>

Expand Down
9 changes: 5 additions & 4 deletions packages/main/test/specs/DatePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,19 +855,20 @@ describe("Date Picker Tests", () => {
await datepicker.openPicker();

const displayedDay = await datepicker.getDisplayedDay(15);

assert.ok(await displayedDay.hasClass("ui5-dp-item--disabled"), "Days out of range are disabled");
});

it("Days are disabled when out of range", async () => {
it("Days are enabled when in range", async () => {
datepicker.id = "#dp33";
const root = await datepicker.getRoot();
await root.keys("Escape");

datepicker.id = "#dp34";
datepicker.id = "#dp33";
await datepicker.openPicker();
const displayedDay = await datepicker.getDisplayedDay(12);

const displayedDay = await datepicker.getDisplayedDay(14);
assert.ok(await displayedDay.isFocusedDeep(), "Days out of range are disabled");
assert.ok(await displayedDay.isFocusedDeep(), "Days in range are enabled");
});

it("Min and Max date are included in the interval", async () => {
Expand Down

0 comments on commit 85c3673

Please sign in to comment.