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

Date Picker Default Initial Month #450

Closed
cierraditmore opened this issue Jan 8, 2024 · 5 comments · Fixed by #472
Closed

Date Picker Default Initial Month #450

cierraditmore opened this issue Jan 8, 2024 · 5 comments · Fixed by #472
Labels
bug Something isn't working complexity: medium prerelease This change relates to a prerelease. priority: medium released This issue/pull request has been released.

Comments

@cierraditmore
Copy link

Describe the bug:
When using the forge-date-picker, if the minimum and maximum values span across two years, the calendar opens to the maximum value month. If the two dates are within the same year, the calendar opens to the minimum date month.

To Reproduce:
Steps to reproduce the behavior:

  1. Set the minimum and maximum dates to dates that span across two years (12/01/2023 and 02/01/2024)
  2. Open the date picker calendar

Expected behavior:
The calendar always defaults to the minimum value month

Please complete the following information:

  • Forge version: 2.13.2
  • I have searched existing issues before creating this report? Yes
  • Browser: All
  • Platform: All
  • OS: All
@samrichardsontylertech
Copy link
Contributor

@cierraditmore

We've found that the calendar is behaving as intended, but agree that this can be confusing so it can be improved.

The issue isn't actually related to min and max dates that span years. It's caused by the calendar attempting to open on a month with enabled dates — if the min date occurs after the current month it goes to the earliest enabled month, and if the max date occurs before the current month it goes to the latest enabled month. Basically the calendar by default takes you to the closest enabled dates. The behavior probably stood out more or seemed especially wrong now because it's close to the beginning of the year.

So we came up with three possible solutions:

  • Leave the calendar as-is
  • Go to the min month if a min date and max date are set and the max date is before the current month
  • Allow the displayed month and year to be manually set on date-picker

Of those the second option seemed to make the most sense for now. The calendar will open on the current date if possible, but if all the enabled dates are in the past it will open on the earliest of those. Here's the PR that implements it — #472

Does that seem like an acceptable solution?

@cierraditmore
Copy link
Author

@samrichardsontylertech

Thanks for the update! I'm not sure I'm understanding the explanation, so I'm going to use examples. I'm referencing the datepicker on the forge dev documentation for this.

When I set the min date to 01/03/2024 and max to 03/26/2024, the calendar opens to the current month (February), which is what I would expect.
When I set the min date to 12/06/2023 and max to 03/26/2024, the calendar opens to March.

Will this change fix the second example, as I would expect it to open to February in either situation? You mention specifically having both the min/max dates in the past, so I just want to clarify.

Thanks!

@samrichardsontylertech
Copy link
Contributor

@cierraditmore

You're absolutely right. Somehow the dates I tested with never ran into this problem, but there are some combinations where the calendar wrongly thinks that the current date is outside the min and max. I updated the PR to fix that.

Specifically, it would test the month and year separately and determine that the date was under/over the min/max if either the month or year was. Changing that to require both fixed the issue.

Thanks for pressing me on it!

@cierraditmore
Copy link
Author

Thanks for taking a look at it again! Everything looks good to me!

@github-actions github-actions bot added the released This issue/pull request has been released. label Feb 15, 2024
Copy link
Contributor

🚀 Issue was released in v3.0.0-next.20 🚀

@github-actions github-actions bot added the prerelease This change relates to a prerelease. label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working complexity: medium prerelease This change relates to a prerelease. priority: medium released This issue/pull request has been released.
Projects
None yet
3 participants