Skip to content

Commit

Permalink
Fix primefaces#3545: Calendar set range programmatically
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Nov 1, 2022
1 parent 7807eed commit 1eb1248
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2496,10 +2496,27 @@ export const Calendar = React.memo(

// #3516 view date not updated when value set programatically
if (!visible && newDate) {
validateDate(newDate);
setViewDateState(newDate);
setCurrentMonth(newDate.getMonth());
setCurrentYear(newDate.getFullYear());
let viewDate = newDate;

if (isMultipleSelection()) {
if (newDate.length) {
viewDate = newDate[newDate.length - 1];
}
} else if (isRangeSelection()) {
if (newDate.length) {
let startDate = newDate[0];
let endDate = newDate[1];

viewDate = endDate || startDate;
}
}

if (viewDate) {
validateDate(viewDate);
setViewDateState(viewDate);
setCurrentMonth(viewDate.getMonth());
setCurrentYear(viewDate.getFullYear());
}
}
}
}, [props.value, visible]);
Expand Down

0 comments on commit 1eb1248

Please sign in to comment.