ui icon indicating copy to clipboard operation
ui copied to clipboard

feat(calendar): add yearselect

Open oof2win2 opened this issue 2 years ago • 6 comments

Add a year and month selector to the calendar component. This is important for usecases such as entry of birthdates, as users would otherwise need to click a lot on the arrows.

image

I have decided to replace the buttons with this PR, however, due to this reason, I believe that this PR is WIP and I welcome any feedback.

oof2win2 avatar May 09 '23 18:05 oof2win2

@oof2win2 is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar May 09 '23 18:05 vercel[bot]

An issue that I have and am not able to fix is the select for the year taking up the whole screen, as seen below. I have attempted to fix this with max-h in multiple components including the base Select component, however, to no avail.

image

oof2win2 avatar May 09 '23 18:05 oof2win2

You could also look at using the captionLayout, fromYear and toYear in the underlying component, with some new CSS rules

            <Calendar 
                  mode="single"
                  selected={date}
                  onSelect={setDate}
                  className="rounded-md border"
                  captionLayout="dropdown-buttons"
                  fromYear={2015} toYear={2025}
            
            />

emrosenf avatar May 09 '23 19:05 emrosenf

The dropdown layout seems cool, and thanks for that - didn't notice it! The issue with it is that it doesn't allow for taking the values that the dropdown itself should display without accessing the internal props of the child elements - which seems relatively hacky for this. Not sure if there is a way to go around that. Checked both the DropdownProps and the DayPickerContext itself.

oof2win2 avatar May 09 '23 19:05 oof2win2

I don't understand the issue, did you try my example?

fromYear and toYear are props.

This is what I did to make a year select

emrosenf avatar May 10 '23 00:05 emrosenf

Yes, I do understand that. The react-day-picker component itself however doesn't allow for customization of the select element with the use of our selects, which I believe is relatively important here to make the the UI seem the same as with other usages of select components. My previous comment was about attempting to style those, which is not possible without taking the internal props as those are not provided.

oof2win2 avatar May 10 '23 05:05 oof2win2

@oof2win2 I think we're going to go with https://github.com/shadcn-ui/ui/pull/1680 which has the most recent updates. But appreciate you starting the work on this. Thank you.

shadcn avatar Oct 21 '23 12:10 shadcn

Sorry, completely forgot about this. Happy that I could have helped even at least a bit 👍

oof2win2 avatar Oct 21 '23 18:10 oof2win2