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

Incorrect year is focused when defaultViewDate is set and startView is set to show decades #187

Open
jochan opened this issue Jun 14, 2024 · 3 comments

Comments

@jochan
Copy link

jochan commented Jun 14, 2024

With the following configs, the decades view is initially shown but when you select the focused decade (1920 in this case), the subsequent focused year is the first year of the selected decade (1920) and not the year in defaultViewDate (1922).

const configs = {
  startView: 3,
  defaultViewDate: "3-10-1922"
}

At first glance, it seems to be due to the year and decade sharing the same view in YearsView, with navStep set incorrectly for the year view (but correctly for the decade view).
https://github.com/mymth/vanillajs-datepicker/blob/master/js/picker/views/YearsView.js#L18

@mymth
Copy link
Owner

mymth commented Jun 15, 2024

It looks like you misunderstand what defaultViewDate is.

The date to be focused when the date picker opens with no selected date(s).
https://mymth.github.io/vanillajs-datepicker/#/options?id=defaultviewdate

The default view date is not the start view date. The start view date is the last selected date, and if no dates are selected, then the default view date is used as a fallback.

I recommend trying selecting a date in a different century and decade from the defaultViewDate's and see what happens.

@jochan
Copy link
Author

jochan commented Jun 17, 2024

In my example, there is no selected date, so it's the defaultViewDate that should be start view date. The key to the issue here is having a startView of 3 (decades), which then makes the incorrect year selection.

It's even evident with no defaultViewDate set, when the current date expected. Here's an example using your online demo with only startView set as 3. You'd expect today's date (06/17/2024) to be focused when using the datepicker but it's actually 06/17/2020 that is focused. Am I still missing something here?

vanillajsdatepicker_example.mp4

@mymth
Copy link
Owner

mymth commented Jun 22, 2024

I'm so sorry, it's me who misunderstood. I didn't read carefully and thought you were talking about the behavior after setting a date in 1920 as a selected date.

It's indeed a bug, and inconsistent with the behavior of other views. So, I'll include the fix for this in the next update.

Thank you for reporting the bug. And my apologies for being careless.

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

No branches or pull requests

2 participants