Skip to content

Commit

Permalink
fix(ui5-date-picker): ensure min and max date are not disabled (#2280)
Browse files Browse the repository at this point in the history
Ensure the Min and Max dates are included in the interval of selectable days.
In addition, correct component sample.
  • Loading branch information
tsanislavgatev committed Oct 1, 2020
1 parent 5ecc51e commit f0473f0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/main/src/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,14 @@ class DayPicker extends UI5Element {

_isOutOfSelectableRange(date) {
const currentDate = date._oUDate ? date.toLocalJSDate() : CalendarDate.fromTimestamp(date).toLocalJSDate();
const minDate = this._minDateObject;
const maxDate = this._maxDateObject;

return currentDate > this._maxDateObject || currentDate < this._minDateObject;
currentDate.setHours(0);
minDate.setHours(0);
maxDate.setHours(0);

return currentDate > maxDate || currentDate < minDate;
}

get _maxDate() {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/test/pages/DatePicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h3>2 months range</h3>
<h3>3 months range</h3>
<ui5-date-picker id="minMax3" value="5/6/2020" min-date="6/1/2020" max-date="5/1/2021" format-pattern="dd/MM/yyyy"></ui5-date-picker>
<h3>1 year range</h3>
<ui5-date-picker id="minMax4" value="5 Feb 2021" min-date="5 Jan 2020" max-date="5 Jan 2021"></ui5-date-picker>
<ui5-date-picker id="minMax4" value="Feb 5, 2020" min-date="Jan 5, 2020" max-date="Jan 5, 2021"></ui5-date-picker>

<section>
<h3>Test ariaLabel and ariaLabelledBy</h3>
Expand Down
10 changes: 10 additions & 0 deletions packages/main/test/specs/DatePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,16 @@ describe("Date Picker Tests", () => {
assert.ok(datepicker.getDisplayedDay(14).isFocusedDeep(), "Days out of range are disabled");
});

it("Min and Max date are included in the interval", () => {
datepicker.id = "#dp33";

datepicker.root.keys("Escape");
datepicker.openPicker({ focusInput: false });

assert.equal(datepicker.getDisplayedDay(9).hasClass("ui5-dp-item--disabled"), false , "Min date is included");
assert.equal(datepicker.getDisplayedDay(11).hasClass("ui5-dp-item--disabled"), false, "Max date is included");
});

it("Tests week numbers column visibility", () => {
// act
datepicker.id = "#dp18";
Expand Down

0 comments on commit f0473f0

Please sign in to comment.