Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui5-calendar): focus the nearest day when today is out of range #6801

Merged
merged 4 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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