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

Implement week picker component #2768

Closed
wants to merge 47 commits into from

Conversation

TiesWestendorp
Copy link
Contributor

@TiesWestendorp TiesWestendorp commented Feb 26, 2021

fixes #2033

Introduces the showWeekPicker setting, which allows picking a week. Internally, the date representing the week is the first day of that week. It's important that the dateFormat prop matches the locale in the sense that they have the same starting day of the week. In the same vein, the selected prop should refer to a date that's at the beginning of a week.

Peek 2021-03-01 16-15

Question 1: should left and right arrows navigate the months, rather than weeks? Answer: no.
Question 2: should the week component be considered selected/keyboard-selected, and the styling be derived from that, or should the days be considered selected/keyboard-selected like they currently are?

@TiesWestendorp
Copy link
Contributor Author

@martijnrusschen or someone else, can you take a look at this PR, and give your take on the questions I posed above?

@tlehtimaki
Copy link

Q2: I think the selecting of all dates in the week seems logical, but then I think you should not be able to individually select the dates.
Q1: For how its implemented now the up/down arrows are logical for browsing the week. The browsing of month suddenly with left/right arrow might be confusing for the user, if user is used to browsing days with those keys.

@TiesWestendorp
Copy link
Contributor Author

Q2: I think the selecting of all dates in the week seems logical, but then I think you should not be able to individually select the dates.

My question was actually more geared towards the internal state; each day component has a 'selected' and 'keyboard-selected' state, which I reuse for the week picker here. Another way would be to not consider these days selected or keyboard-selected in this case, but the week component that wraps these days. There's a bit of a trade-off here: the former option borrows heavily from the existing styling, meaning it doesn't introduce much complexity in the stylesheets, but is potentially less flexible. As to your comment: clicking on a particular date will currently select the corresponding date - do you mean to say that you don't agree with this? My issue with that is that when the week numbers are not present you won't have a meaningful thing to click on. A takeaway from this may be that the week numbers should always be shown when the week picker is used, but that is also currently not the case.

Q1: For how its implemented now the up/down arrows are logical for browsing the week. The browsing of month suddenly with left/right arrow might be confusing for the user, if user is used to browsing days with those keys.

I agree, but wanted to lay the options on the table. 👍 Currently left/right behave the same as up/down in the week picker.

@tlehtimaki
Copy link

I understood that the concept would be to select just weeks, so I thought there would be no need to select a single date, but here that single date would convert in to the week that the date belongs to.

@TiesWestendorp
Copy link
Contributor Author

I understood that the concept would be to select just weeks, so I thought there would be no need to select a single date, but here that single date would convert in to the week that the date belongs to.

Correct, just having the week number select the first date of a week was already possible by using a callback on the week number. What this PR introduces is the additional logic required to properly display the state, changed keyboard navigation to match and a fallback that ensures the first day of a week is always used.

@TiesWestendorp
Copy link
Contributor Author

Could some one take a look at why the specs are failing? I'm not really sure what's going wrong.

@martijnrusschen
Copy link
Member

martijnrusschen commented Mar 10, 2021 via email

@TiesWestendorp
Copy link
Contributor Author

@martijnrusschen Could you still have a look at this PR?

@martijnrusschen
Copy link
Member

martijnrusschen commented May 5, 2021

This looks good! Can you resolve the merge conflict so I can merge it in? I'm prepping a major release for this week and would love to get this in.

@TiesWestendorp
Copy link
Contributor Author

👍 Done.

@martijnrusschen
Copy link
Member

I ran the tests, and it looks like there's some things breaking. Can you take a look?

@TiesWestendorp
Copy link
Contributor Author

Should be fixed now.

className={classnames(weekNumberClasses)}
aria-label={`${ariaLabelPrefix} ${this.props.weekNumber}`}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this is removed completely?

@@ -0,0 +1,53 @@
import React from "react";
Copy link
Member

Choose a reason for hiding this comment

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

Thinking a bit on code coverage.. Might be good to add some tests that checks the behavior of showing/hiding the weekpicker as well. Making sure the weekpicker isn't shown when the prop isn't passed in and shown when it is passed in.

Copy link
Member

Choose a reason for hiding this comment

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

Codecov added some comments on coverage as well, would be great to improve the coverage to make sure we don't break this in the future.

Copy link
Member

@martijnrusschen martijnrusschen left a comment

Choose a reason for hiding this comment

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

Let's improve the test coverage to make sure we won't break this in the future.

@georgecosmin98
Copy link

Hello!

Any news about week-picker? When can we expect a release?

@johnnyxbell
Copy link

Any news on when we can get this merged?

@Sozh-Max
Copy link

Why is it taking so long?

@manzoorwanijk
Copy link

Any update on this?

@nacimgoura
Copy link

When will this feature be merged?

@arikm66
Copy link

arikm66 commented Jul 19, 2021

I really need this feature :) When will it be merged?

@martijnrusschen
Copy link
Member

Perhaps someone can take a look and bring this to the finish line.

@Seaviello
Copy link

Seaviello commented Aug 11, 2021

We are also currently interested in that feature. Is there something that outsider can do to help you out with making this happen or right now it's mostly in the reviewers' hands?

@agathepey
Copy link

Hey 👋 ! Any news about the merge? We really need this feature too :) Thank you in advance 🙏

@akashraj9828
Copy link

Any update on this... really need this feature. Thanks in advance.

@akashraj9828
Copy link

Not sure if anyone needs this anymore but I was able to implement the week picker with the existing library...
Demo:
https://codesandbox.io/s/react-datepicker-example-forked-89fn7?file=/src/WeekPicker.tsx

@correahi
Copy link

correahi commented Oct 7, 2021

Hey guys, just in case anyone still needs a week picker, I came up with a solution that worked pretty well for my needs.

I used the dayClassName prop to attach the "react-datepicker__day--selected" className to every day in the week that's selected using date-fns
image

Then I use a little bit of CSS to highlight the whole week on hover
image

Which gives me this result, visually
SRDy4h6biZ

From there, I just put this on my onChange handler so I can access the first and last day of the week, which is what I needed. You could also use other date-fns functions to get an array of all the days or the number of the week.

image

Keyboard navigation also works, since all you're doing is selecting a single day, everything else is just CSS trickery.

@ngajhede
Copy link

Hey @correahi! Thanks for this. I was wondering how you display the startDate to endDate in the input box?

@correahi
Copy link

correahi commented Feb 12, 2022

Hey @correahi! Thanks for this. I was wondering how you display the startDate to endDate in the input box?

I don't have access to that codebase anymore but I'm pretty sure it's just a span with some text inside, something like ${startOfISOWeek(selectedDate)} to ${endOfISOWeek(selectedDate)} and onClick it opens the datepicker, it's not the default input.

@stale
Copy link

stale bot commented Jun 12, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 12, 2022
@stale stale bot closed this Jul 10, 2022
@gtaylor44
Copy link

Will this be merged into master?

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

Successfully merging this pull request may close these issues.

Can we have a week picker ?