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: display calendar in a valid month when month prop is invalid #2672

Merged
merged 2 commits into from
Jan 25, 2025

Conversation

rodgobbi
Copy link
Collaborator

What's Changed

Passing a month prop that is outside the startMonth and endMonth range breaks the calendar.
The PR fixes this edge case by always displaying a valid month as suggested in #2671 (comment).

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

@@ -96,7 +96,8 @@ export function useCalendar(
const initialMonth = getInitialMonth(props, dateLib);
const [firstMonth, setFirstMonth] = useControlledValue(
initialMonth,
props.month ? startOfMonth(props.month) : undefined
// initialMonth is always computed from props.month if provided
props.month ? initialMonth : undefined
Copy link
Owner

@gpbl gpbl Jan 25, 2025

Choose a reason for hiding this comment

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

Good catch! I always thought that useControlledValue call was hiding some bugs.

Worth to add a test case to getInitialMonth.test.ts. Would you add one? Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For sure, just pushed more tests 👍
I think getInitialMonth.test.ts was testing well in most of the use cases with the month prop, but in any case, I expanded existing tests and added more.
Let me know if you think it would be useful to add tests for the useCalendar specifically. We may not need it because it's indirectly tested by other test cases.

Copy link
Owner

@gpbl gpbl left a comment

Choose a reason for hiding this comment

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

Looking great, thanks @rodgobbi 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants