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

feat(calendar): enhance calendar component with dropdown selector #1680

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

auzeonfung
Copy link

@auzeonfung auzeonfung commented Oct 5, 2023

Previously, users had to continuously click the previous/next month button to navigate through months, which was not very user-friendly.

In this update, I have added the ability for users to directly specify a year or month through a dropdown selector.

Differences in this change compared to PR #918 :

  • Optimized the component style, especially for scenarios where three or more months are displayed simultaneously.
  • Enabled scrolling in the dropdown list for year and month selection when the height exceeds the screen size.
  • Resolved TypeScript type errors that were present in the previous PR, ensuring successful project compilation and pnpm test command passed.

In addition to these changes, this PR also includes appropriate modifications to the project's documentation pages related to the calendar and date-picker components to reflect the aforementioned changes to the components.

Hope this PR can be merged as soon as possible. If there are any issues with the code, everyone's feedback and suggestions is welcome.

## Support for selecting the year and month using the select component.

Related to:

shadcn-ui#320 shadcn-ui#546 shadcn-ui#509 shadcn-ui#880 

### Usage:
```
<Calendar
    initialFocus
    mode="range" // range | single
    captionLayout="dropdown-buttons" 
    // Optionally, enables the year and month drop-down selector.
    // also: dropdown-buttons | dropdown | buttons
    fromYear={2022} 
    toYear={2023} 
    defaultMonth={date?.from}
    selected={date}
    onSelect={setDate}
    numberOfMonths={2}
    {...props}
/>
```

---
ZEONFUNG, NGAU
[email protected] #230713 142000
@vercel
Copy link

vercel bot commented Oct 5, 2023

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

A member of the Team first needs to authorize it.

@auzeonfung
Copy link
Author

image image image image image image image

@auzeonfung
Copy link
Author

Related to:

#320 #546 #509 #880

@JuGit-pk
Copy link

JuGit-pk commented Oct 9, 2023

please approve it, this need to be fixed ASAP

@limitless-dev
Copy link
Contributor

Awesome job!
Would be nice to tweak dropdown to only show months that are within date range (fromDate, toDate).

@auzeonfung
Copy link
Author

Awesome job! Would be nice to tweak dropdown to only show months that are within date range (fromDate, toDate).

You've reminded me! This is the part I didn't notice, I'll find the time to implement this part. ;)

@iaingymware
Copy link
Contributor

I see that currently on the Calendar component you can set "captionLayout" to "buttons" or "dropdown" however when configuring "dropdown", the UI is broken:

image

Does this feature resolve this issue?

Thanks

@auzeonfung
Copy link
Author

I see that currently on the Calendar component you can set "captionLayout" to "buttons" or "dropdown" however when configuring "dropdown", the UI is broken:
Does this feature resolve this issue?

Yes.

@shadcn shadcn added enhancement New feature or request component: calendar area: roadmap This looks great. We'll add it to the roadmap, review and merge. labels Oct 18, 2023
@vercel
Copy link

vercel bot commented Oct 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2023 5:42pm

@puneetv05
Copy link

Hey, this PR has been hanging around quite a while, It's a really cool feature <3 we're all waiting for .
Keen to help out wherever I can!

row: "flex w-full mt-2",
cell: "text-center text-sm p-0 relative [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20",
cell: cn(
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent",

Choose a reason for hiding this comment

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

add h-9 w-9 [otherwise if you set showOutsideDays to false the cells will not show in their proper location]

@qasimgit
Copy link

qasimgit commented Mar 4, 2024

@auzeonfung @shadcn Are conflicts the reason for not merging this PR?

@krouskystepan
Copy link

Just one small detail... When u have "new york" selected it changes the width of the calendar... It's just a small thing, but I think it can can be fixed...

Screen.Recording.2024-03-06.at.0.59.21.mov

@Mr0nline
Copy link

Mr0nline commented Apr 1, 2024

Hey all, We'd really love for this feature to be merged! So bumping this PR! 👍

@jacoblsdev
Copy link

Hello @shadcn , There are some code conflicts. Please merge this ASAP.

@urwah1248
Copy link

Hey everyone!
I think this feature is necessarily needed. Even from the forms example, this is pretty clear. How are we supposed to select the birth year.
image

@BuckLearnsCode
Copy link

@shadcn team - this is a must add. Can we please get this into build?

@BuckLearnsCode
Copy link

To clarify, the usability bug I'm hitting that makes the date selector unbearable is that as you flip through months with different number of days, the calendar height changes and the tap target moves to scroll through months. Then the dialogue closes. To move 5-6 months in advance is painful, and that's for me who uses this every day, let alone new users.

I see this is fixed which is why I request change in next build.

@BuckLearnsCode
Copy link

Last comment from me - the usability bug I mentioned only happens when the Calendar Dialogue opens ABOVE the input field. When below, scrolling through works perfectly. I'll see if I can persist this on my app to solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: roadmap This looks great. We'll add it to the roadmap, review and merge. component: calendar enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.