rehookify / datepicker

The ultimate tiny tool for creating date and range pickers in your React applications.

Home Page:https://rehookify.com/datepicker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

previous and next year actions

tamazlykar opened this issue · comments

Hi. I want to propose a new feature that will help to build different types of calendars.
In the dev app, you have the next setup:
Screenshot 2023-01-25 at 15 00 08
Previous and Next buttons in the day view are changing the current month by one.
Previous and Next buttons in the month view are changing the current month by one as well.
Previous and Next buttons in the year view are changing the current year by decades and do not update a current year.

I think there is also could be actions (prop getters) that will change the current year by one. This will be fit to the month view in the dev app.
The nextYearsButton with a step = 1 not works well in this case, because if I want to connect this button to a month view with the minDate / maxDate setting I got the wrong disabled state of the button.

In any case, the API of the library allows you to implement all this manually, but perhaps this will be in demand by other developers.

The role of next/previous month/year is to move offsetDate.
I have an idea to allow configuring a step of next/previous month's prop-getters so users could do things like this:
...nextMonth(month, { step: 12 }) - it will be equal to moving offsetDate 1 year to the future.
A good point is to expose offsetDate to help developers determine what offset is.
Also, as quick enhancement could be to accept offset in setNexMonth, setPreviousMonth actions.

@tamazlykar, hello again. :)
I think that v4.3.0 will help to move 1 year back and forward.
Just pass { step: 12 } to the previousMonthButton and nextMonthButton and it is ready to go.

@Feshchenko, hello :)
Thank you so much. I tried and found some issue in behaviour.
I make some reproduction of the issue (this is your example with a configured step and minDate/maxDate).
To reproduce:

  1. select January
  2. See that the previous year button becomes disabled.
    The same issue will be if you choose any month in the previous year (except a current one - February).

The role of next/previous month/year is to move offsetDate.
I have an idea to allow configuring a step of next/previous month's prop-getters so users could do things like this:
...nextMonth(month, { step: 12 }) - it will be equal to moving offsetDate 1 year to the future.
A good point is to expose offsetDate to help developers determine what offset is.
Also, as quick enhancement could be to accept offset in setNexMonth, setPreviousMonth actions.

@Feshchenko Thank you for you contributions. It would be nice if this information is more clearly stated in the repo documentation and would be much more appreciated if this is also updated in the code sandbox examples.