Skip to content

Commit

Permalink
fix: make calendar render correctly when maxDate is set #170
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanjones243 authored and jason-capsule42 committed Jan 17, 2025
1 parent c87c475 commit a912b52
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions components/datepicker/src/auro-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,11 +844,14 @@ export class AuroDatePicker extends LitElement {
// a later date than the current value date
if (changedProperties.has('minDate')) {
if (this.minDate) {
const minDateMonth = Number(this.minDate.charAt(1));
const minDateMonth = Number(this.minDate.split('/')[0]);
const minDateYear = Number(this.minDate.split('/')[2]);

// This sets the visible month of the calendar to the minDate when the minDate is later
// than the current visible date
if (minDateMonth > this.calendar.month) {
if (minDateYear > this.calendar.year) {
this.calendarRenderUtil.updateCentralDate(this, this.minDate);
} else if (minDateYear === this.calendar.year && minDateMonth > this.calendar.month) {
this.calendarRenderUtil.updateCentralDate(this, this.minDate);
}

Expand All @@ -869,6 +872,17 @@ export class AuroDatePicker extends LitElement {
// This resets the datepicker when the maxDate is set to a new value that is
// an earlier date than the current value date
if (changedProperties.has('maxDate')) {
const maxDateMonth = Number(this.maxDate.split('/')[0]);
const maxDateYear = Number(this.maxDate.split('/')[2]);

// This sets the visible month of the calendar to the maxDate when the maxDate is earlier
// than the current visible date
if (maxDateYear < this.calendar.year) {
this.calendarRenderUtil.updateCentralDate(this, this.maxDate);
} else if (maxDateYear === this.calendar.year && maxDateMonth < this.calendar.month) {
this.calendarRenderUtil.updateCentralDate(this, this.maxDate);
}

if (this.maxDate) {
if (this.value) {
if (new Date(this.maxDate).getTime() < new Date(this.value).getTime()) {
Expand Down

0 comments on commit a912b52

Please sign in to comment.