ui icon indicating copy to clipboard operation
ui copied to clipboard

[Bug]: Date Picker not usable for Selecting Birth Date, despite this use case being advertised.

Open johanneskares opened this issue 1 year ago • 1 comments
trafficstars

Describe the bug

Has anyone actually tried to use the date picker for selecting your bith date?

Screenshot 2024-03-11 at 16 50 55

It's basically impossible, because you can't select the year.

Affected component/components

Date Picker, Calendar

How to reproduce

Obvious

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

all browsers

Before submitting

  • [X] I've made research efforts and searched the documentation
  • [X] I've searched for existing issues

johanneskares avatar Mar 11 '24 15:03 johanneskares

For anyone looking for a solution, here is a small modification to the component that works for me.

Screenshot 2024-03-11 at 17 43 22
<Calendar
    selected={field.value}
    onSelect={field.onChange}
    disabled={(date) => date > new Date() || date < new Date("1900-01-01")}
    captionLayout="dropdown"
    toYear={2010}
    fromYear={1900}
    classNames={{
        day_hidden: "invisible",
        dropdown: "px-2 py-1.5 rounded-md bg-popover text-popover-foreground text-sm  focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ring-offset-background",
        caption_dropdowns: "flex gap-3",
        vhidden: "hidden",
        caption_label: "hidden",
    }}
    initialFocus
/>

I'm happy to create a PR to add this as a variant.

johanneskares avatar Mar 11 '24 16:03 johanneskares

really nice @johanneskares I guess I took a hard route and just used another component. Tremendously helpful!

TheZodo avatar Mar 12 '24 06:03 TheZodo

@johanneskares
its fine but when you select calendar and re-open , its reseted. how can we fix it?

Nikkakko avatar Mar 15 '24 06:03 Nikkakko

@johanneskares its fine but when you select calendar and re-open , its reseted. how can we fix it?

https://react-day-picker.js.org/basics/navigation

you have to pass the current field value to the defaultMonth prop.

camposvictor avatar Mar 16 '24 01:03 camposvictor

it would be great when this works for range too... if i change the date in the caption it changes for both calendar views...

nathanielrich avatar Apr 17 '24 10:04 nathanielrich

This is a great ticket and solution, thank you!

dmr avatar Jun 13 '24 09:06 dmr

Thanks! Hopefully the calendar can work as expected with the property captionLayout='dropdown' with an update.

DallasBelt avatar Jul 11 '24 14:07 DallasBelt

feel free to use this variant. you will need react-day-picker v9 or above: https://github.com/shadcn-ui/ui/pull/4421

I think this is better UX than a Select Dropdown, it is inspired by: https://material.angular.io/components/datepicker/overview

flixlix avatar Jul 26 '24 13:07 flixlix