Skip to content

Conversation

@Coderxrohan
Copy link
Contributor

Fix: Calendar displays incorrect value when controlled value is not updated

Problem

When the Calendar component is used as a controlled component, it updates its input field optimistically on date selection.
If the parent component intentionally does not update the value in onChange (e.g. user cancels a confirmation dialog), the input temporarily displays an incorrect date.

Solution

  • Removed optimistic input updates on date selection
  • Ensured the input value is always derived from props.value
  • Input now updates only when the external value actually changes

This restores proper controlled component behavior and fixes issue #7428.

Reproducer

https://codesandbox.io/p/sandbox/primereact-calendar-displays-incorrect-value-if-new-value-was-not-applied-in-onchange-sw2547

Calendar: incorrect value is displayed #7428

@Coderxrohan
Copy link
Contributor Author

The final change stabilizes the Calendar input sync by keeping the latest updateInputfield via a ref, avoiding unstable hook dependencies while preserving existing behavior.

@melloware melloware linked an issue Jan 2, 2026 that may be closed by this pull request
@melloware melloware force-pushed the fix/calendar-controlled-value branch from a90042a to 82d8257 Compare January 2, 2026 12:06
@melloware melloware merged commit f01edcf into primefaces:master Jan 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calendar: incorrect value is displayed

2 participants