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

Fix/33006 #33355

Merged
merged 4 commits into from
Jan 8, 2024
Merged
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
34 changes: 32 additions & 2 deletions src/components/DatePicker/CalendarPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,44 @@ class CalendarPicker extends React.PureComponent {
* Handles the user pressing the previous month arrow of the calendar picker.
*/
moveToPrevMonth() {
this.setState((prev) => ({currentDateView: subMonths(new Date(prev.currentDateView), 1)}));
this.setState((prev) => {
const prevMonth = subMonths(new Date(prev.currentDateView), 1);
// if year is subtracted, we need to update the years list
let newYears = prev.years;
if (prevMonth.getFullYear() < prev.currentDateView.getFullYear()) {
newYears = _.map(prev.years, (item) => ({
...item,
isSelected: item.value === prevMonth.getFullYear(),
}));
}

return {
currentDateView: prevMonth,
years: newYears,
};
});
}

/**
* Handles the user pressing the next month arrow of the calendar picker.
*/
moveToNextMonth() {
this.setState((prev) => ({currentDateView: addMonths(new Date(prev.currentDateView), 1)}));
this.setState((prev) => {
const nextMonth = addMonths(new Date(prev.currentDateView), 1);
// if year is added, we need to update the years list
let newYears = prev.years;
if (nextMonth.getFullYear() > prev.currentDateView.getFullYear()) {
newYears = _.map(prev.years, (item) => ({
...item,
isSelected: item.value === nextMonth.getFullYear(),
}));
}

return {
currentDateView: nextMonth,
years: newYears,
};
});
}

render() {
Expand Down
Loading