Skip to content

Commit

Permalink
fix(calendar): fixed a bug where setting a min date to the following …
Browse files Browse the repository at this point in the history
…year would not properly default the initial month/year to the correct date
  • Loading branch information
DRiFTy17 committed Dec 12, 2023
1 parent 468530e commit 00e41b1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/lib/calendar/calendar-foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,8 @@ export class CalendarFoundation implements ICalendarFoundation {
private _applyMin(): void {
this._adapter.toggleHostAttribute(CALENDAR_CONSTANTS.attributes.MIN, !!this._minAttribute, this._minAttribute as string);

if (this._min && this._min.getMonth() > this._month) {
if (this._min && (this._min.getMonth() > this._month || this._min.getFullYear() > this._year)) {
this._year = this._min.getFullYear();
this._month = this._min.getMonth();
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/spec/date-picker/date-picker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ describe('DatePickerComponent', function(this: ITestContext) {
openPopup(this.context.component);
const calendar = getCalendar(this.context.component);

expect(calendar.month).toEqual(date.getMonth() + 1);
const expectedMonth = date.getMonth() >= 11 ? 0 : date.getMonth() + 1;
expect(calendar.month).toEqual(expectedMonth);
});

it('should open calendar in month of max date if max is before current month', function(this: ITestContext) {
Expand Down

0 comments on commit 00e41b1

Please sign in to comment.