Skip to content

Commit

Permalink
Fix #5973: Calendar yearNavigator defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Feb 15, 2024
1 parent 77eecd3 commit ba84e0d
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3172,14 +3172,37 @@ export const Calendar = React.memo(
};

const createTitleYearElement = (metaYear) => {
const displayYear = props.numberOfMonths > 1 ? metaYear : currentYear;

if (props.yearNavigator) {
let yearOptions = [];
const years = props.yearRange.split(':');
const yearStart = parseInt(years[0], 10);
const yearEnd = parseInt(years[1], 10);

for (let i = yearStart; i <= yearEnd; i++) {
yearOptions.push(i);
if (props.yearRange) {
const years = props.yearRange.split(':');
const yearStart = parseInt(years[0], 10);
const yearEnd = parseInt(years[1], 10);

for (let i = yearStart; i <= yearEnd; i++) {
yearOptions.push(i);
}
} else {
let base = displayYear - (displayYear % 10);

const isSelectableYear = (baseYear) => {
if (props.minDate) {
if (props.minDate.getFullYear() > baseYear) return false;
}

if (props.maxDate) {
if (props.maxDate.getFullYear() < baseYear) return false;
}

return true;
};

for (let i = 0; i < 10; i++) {
isSelectableYear(base + i) && yearOptions.push(base + i);
}
}

const viewDate = getViewDate();
Expand Down Expand Up @@ -3231,7 +3254,6 @@ export const Calendar = React.memo(
return content;
}

const displayYear = props.numberOfMonths > 1 ? metaYear : currentYear;
const yearTitleProps = mergeProps(
{
className: cx('yearTitle'),
Expand Down

0 comments on commit ba84e0d

Please sign in to comment.