-
-
Notifications
You must be signed in to change notification settings - Fork 741
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: enable all years available in the year select dropdown #2614
Conversation
@gpbl I found other potential improvements to the behavior of the day picker with the dropdown layout, which I'd like to share with you to discuss if they make sense and if they'd improve the day picker. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @rodgobbi, thanks a lot for your PR.
I’ve been trying solution with the test case for #2549, but it doesn’t work as expected.
Here’s the code:
import { DayPicker } from “react-day-picker”;
export function Dropdown() {
const from = new Date(2024, 9);
const to = new Date(2025, 1);
return <DayPicker startMonth={from} endMonth={to} captionLayout="dropdown" />;
}
This does render the list of disabled months, but January 2025 and February 2025 are not navigable via the dropdown menu.
Screen.Recording.2024-12-05.at.5.38.29.PM.mov
What I would try:
- Never disable the select options.
- When a select option changes, call
useCalendar().goToMonth
:
calendar.goToMonth(
new Date(yearDropdownValue, monthDropdownValue)
);
goToMonth() function already navigates to the correct month if the selected option is not available.
...if I haven’t overlooked anything, this solution could resolve the issue.
What do you think?
Feel free to open a new issue! Thanks for asking! |
FYI @gpbl, this PR is already doing what you suggested 😅, I've added a screen recording to the PR to help visualize. |
Sorry, my bad! Something was off when checking out the PR. I do see it works now! Let me give the code changes a review. 👀 I do still see an issue with the code below, where some months are not displayed. I think this is another bug as it happens also on the main branch. export function Dropdown() {
const from = new Date(2024, 9);
const to = new Date(2025, 1);
return <DayPicker startMonth={from} endMonth={to} captionLayout="dropdown" />;
} ![]() |
Thanks again for your work @rodgobbi ! |
Happy to help @gpbl |
What's Changed
Enable all years available in the year select dropdown. If after selecting the year, the selected month is before the
startMonth
or after theendMonth
, the day picker selects the closest valid month.Fix #2549
Type of Change
Demo
Screen.Recording.2024-12-06.at.18.33.14.mov