Shadcn Date Picker sucks! So I’ve built my own.

Shadcn Date Picker component definitely does not suck, excuse my click bait, but there are a couple of use cases where using this component is not ideal, for example, selecting date of birth, let’s explore why.

Shadcn implementation

If you look at the example from shadcn/ui date picker, selecting your Date of Birth would mean that you would have to click on the left arrow for ages to get to let’s say 1983. It’s not possible to select a year nor month. Even if you could, examples of these implementations are not very intuitive for users, from my experience.

shadcn date picker

Solution

Date Picker from shadcn was built using a combination of Popover and the Calendar. Instead of using Calendar I am using Select and ScrollArea components. And that looks like this:

Simple Date Picker with Shadcn

As you can see user can select day, month and a year, which in my opinion is faster and easier. You can check out the demo here.

How to use

To use this component just install Select and ScrollArea components (and shadcn obviously). Copy simple-date-picker.tsx from here and save it inside /components. Finally, import SimpleDatePicker in your page, and use it, for example:

 <SimpleDatePicker startYear={1930} endYear={2030} selected={date} onSelect={setDate} />
Enter fullscreen mode Exit fullscreen mode

As you can see, you can select start year and end year based on your needs, date picker also has some validation, for example it will throw an error if user selects 31/2.

That’s it, hope you enjoyed this post! If you tried this simple component I would love to know what you think feel free to comment or let’s connnect on x.com.


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Choose overlaxed for affordable vps hosting plans that don’t compromise on quality. Cloudystorage offers affordable online storage solutions tailored to meet the needs of both individual users and businesses.