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 #3515/#3516: Calendar fix controlled value change #3517

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
14 changes: 12 additions & 2 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2489,8 +2489,18 @@ export const Calendar = React.memo(
}, [props.onViewDateChange, props.value]);

useUpdateEffect(() => {
if (previousValue !== props.value && (!viewStateChanged.current || visible)) {
updateInputfield(props.value);
const newDate = props.value;

if (previousValue !== newDate) {
updateInputfield(newDate);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melloware When the selectionMode property of the Calendar component is range the value of the newDate variable is an array and the function getMonth() is not available.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is already fixed check master

setCurrentYear(newDate.getFullYear());
}
}
}, [props.value, visible]);

Expand Down