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

Upgrade react-day-picker to v9 #4371

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

Conversation

AhmedBaset
Copy link
Contributor

@AhmedBaset AhmedBaset commented Jul 22, 2024

Close #4366

I'm opening this PR as early as possible to avoid the issues we had with <Command /> when cmdk v1.0 was released. And to make it easy for current users to upgrade in their codebases by copying the new update.

This PR upgrades react-day-picker to the latest v9

See Changelog and Upgrade Guide

Notable Changes:

  • Renaming some classNames
  • date-fns is now a dependency rather than a peer dependency

TODOs:

  • Pin react-day-picker to 9.0 to avoid the same issue with the next major
x o
default image
new-york image

To upgrade in your codebase:

  • pnpm update react-day-picker@9
  • pnpm un date-fns If you don't use it anywhere else
  • Wait the next shadcn-ui release and run shadcn-ui add calendar --overwrite or copy the source code directly for default or new york styles.

Copy link

vercel bot commented Jul 22, 2024

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

A member of the Team first needs to authorize it.

@AhmedBaset AhmedBaset changed the title Migrate react-day-picker to v9 Upgrade react-day-picker to v9 Jul 22, 2024
@valentinpolitov
Copy link

Thanks, @AhmedBaset, appreciate your work on this. However, I believe there's a bit more to address regarding Tailwind. In react-day-picker v9, the aria-selected attribute has been moved from cell day_button to row day. This component relies heavily on that attribute, so additional adjustments are needed.

@AhmedBaset
Copy link
Contributor Author

Thanks, @AhmedBaset, appreciate your work on this. However, I believe there's a bit more to address regarding Tailwind. In react-day-picker v9, the aria-selected attribute has been moved from cell day_button to row day. This component relies heavily on that attribute, so additional adjustments are needed.

Thanks for the feedback. It's still WIP.

@shadcn shadcn added area: roadmap This looks great. We'll add it to the roadmap, review and merge. component: calendar labels Jul 23, 2024
@shadcn
Copy link
Collaborator

shadcn commented Jul 23, 2024

@AhmedBaset Thanks for your work here. I've pinned react-day=picker to v8 for now. Let me know when this is ready for upgrade.

(Ideally, if you get to it, it would be great to document the upgrade on the calendar page. See https://ui.shadcn.com/docs/components/input-otp#changelog as an example).

Copy link

vercel bot commented Jul 23, 2024

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 Jul 23, 2024 7:16am

@flixlix
Copy link
Contributor

flixlix commented Jul 26, 2024

@shadcn made a similar PR here #4421
just noticed this one now, but my PR also adds a new feature, feel free to review it :)

@AhmedBaset AhmedBaset marked this pull request as ready for review July 31, 2024 07:26
@AhmedBaset
Copy link
Contributor Author

Pinging @shadcn to review

@Christophvh Christophvh mentioned this pull request Aug 7, 2024
2 tasks
@Christophvh
Copy link

v9 adds new functionality which also breaks extra styling:
<DayPicker hideNavigation captionLayout="dropdown" />

https://daypicker.dev/docs/navigation#hidenavigation

@Nhollas
Copy link

Nhollas commented Aug 12, 2024

Hello all!

Please take a look at:

Version 9

Version 8

I'm new to open-source, what's normally the way that people contribute?

The code for above lives here.

My approach is aware of the switch RDP made with the aria-selected attributes and seems to be exactly matching the styles of v8. I had hoped to write some UI regression tests with storybook but it wasn't that great at detecting the subtle visual changes.

Currently having some teething issues with the navigation positioning when use opt to use a custom dropdown:

          <Calendar
            mode="single"
            captionLayout="dropdown"
            selected={date}
            onSelect={setDate}
            showOutsideDays={true}
            endMonth={new Date(2099, 11)}
            components={{
              Dropdown: MonthAndYearDropdown,
              Chevron: ({ orientation }) =>
                orientation === "left" ? (
                  <ChevronLeft className="size-4" />
                ) : (
                  <ChevronRight className="size-4" />
                ),
            }}
          />

Code for the above can be found here.

-Nick

@kachkaev kachkaev mentioned this pull request Aug 30, 2024
2 tasks
Copy link

@TomHawk123 TomHawk123 left a comment

Choose a reason for hiding this comment

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

I had to do the same

Comment on lines +62 to +73
modifiers?.today && "bg-accent text-accent-foreground",
modifiers?.selected &&
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
modifiers?.outside &&
"text-muted-foreground opacity-50 pointer-events-none",
modifiers?.disabled && "opacity-50 text-muted-foreground",
modifiers?.hidden && "invisible",
modifiers.range_middle &&
"bg-accent text-accent-foreground hover:bg-accent hover:text-accent-foreground rounded-none last:rounded-e-md first:rounded-s-md",
modifiers.outside &&
modifiers.selected &&
"bg-accent/40 text-muted-foreground"
Copy link

@McTom234 McTom234 Sep 20, 2024

Choose a reason for hiding this comment

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

If this is going to be pursued, the code could be made a bit more readable with the ClassDictionary from clsx. Instead of having these && operators in every row, an object could be used like this:

Suggested change
modifiers?.today && "bg-accent text-accent-foreground",
modifiers?.selected &&
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
modifiers?.outside &&
"text-muted-foreground opacity-50 pointer-events-none",
modifiers?.disabled && "opacity-50 text-muted-foreground",
modifiers?.hidden && "invisible",
modifiers.range_middle &&
"bg-accent text-accent-foreground hover:bg-accent hover:text-accent-foreground rounded-none last:rounded-e-md first:rounded-s-md",
modifiers.outside &&
modifiers.selected &&
"bg-accent/40 text-muted-foreground"
"bg-accent text-accent-foreground": modifiers?.today,
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground": modifiers?.selected,
"text-muted-foreground opacity-50 pointer-events-none": modifiers?.outside,
"opacity-50 text-muted-foreground": modifiers?.disabled,
invisible: modifiers?.hidden,
"bg-accent text-accent-foreground hover:bg-accent hover:text-accent-foreground rounded-none last:rounded-e-md first:rounded-s-md": modifiers?.range_middle,
"bg-accent/40 text-muted-foreground": modifiers?.outside && modifiers?.selected

Also, I noted that some modifiers values don't have the ?. Don't know if it'd be a possible issue...

After looking into the daypicker types, I guess the ? could be entirely removed for modifiers?

Copy link

Choose a reason for hiding this comment

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

I came across this PR while updating day picker in my project.

An object like what @McTom234 suggested is definitely cleaner but the previous code (e.g. cell: ... before it changed to day) was targeting aria-selected to add styling instead, maybe it would be better to keep that approach instead of importing Button? Anyways that's what I'll be doing.

Also I think lines like "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground": modifiers?.selected, can be cleaned up since the default/hover/focus styles are the same, unless they're overriding styles set somewhere else.

Choose a reason for hiding this comment

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

I agree on those lines, although the others are cleaner. I tried to upgrade to v9 myself, but didn't have the time to get a working solution done, so I stayed at v8 for now. But during the process, I felt like importing Button wasn't a big gain.

Anyways, if you have a working solution example, I'd appreciate a little insight 😇

Copy link

Choose a reason for hiding this comment

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

@McTom234 for me, following the react-day-picker upgrading doc fixed most of the regressions. Seems like v9's HTML structure is different though so updating the nav buttons positioning isn't as straightforward. I'm working on that now but I'm using nav: "flex items-start", to have the nav float up to the top, absolute left-2 and absolute right-2 on button_previous and button_next respectively, and months: "flex flex-col sm:flex-row", month: "m-4 mb-0 last-of-type:ml-0", to adjust/fix some other layout regressions. Our calendar component is pretty heavily customized so I'm afraid that sharing it will be more noisy than helpful.

Choose a reason for hiding this comment

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

Okay, thanks for your tips. I followed the same guide and had the issues with the nav buttons as well. That's where time-benefit wasn't given to proceed...

@uschen
Copy link

uschen commented Oct 9, 2024

here

Hello all!

Please take a look at:

Version 9

Version 8

I'm new to open-source, what's normally the way that people contribute?

The code for above lives here.

My approach is aware of the switch RDP made with the aria-selected attributes and seems to be exactly matching the styles of v8. I had hoped to write some UI regression tests with storybook but it wasn't that great at detecting the subtle visual changes.

Currently having some teething issues with the navigation positioning when use opt to use a custom dropdown:

          <Calendar
            mode="single"
            captionLayout="dropdown"
            selected={date}
            onSelect={setDate}
            showOutsideDays={true}
            endMonth={new Date(2099, 11)}
            components={{
              Dropdown: MonthAndYearDropdown,
              Chevron: ({ orientation }) =>
                orientation === "left" ? (
                  <ChevronLeft className="size-4" />
                ) : (
                  <ChevronRight className="size-4" />
                ),
            }}
          />

Code for the above can be found here.

-Nick

NICE!

-> months: 'flex flex-col sm:flex-row gap-y-4 sm:gap-x-4 sm:gap-y-0', needs relative it seems

@lukasbindreiter
Copy link

lukasbindreiter commented Nov 5, 2024

@shadcn Is there any ETA or planned time when this will be merged? We are waiting quite eagerly for this for a while now already. We mainly want to upgrade due to the UTC dates support in react day picker v9, which we need for our use-case.

"aria-selected:bg-accent aria-selected:text-accent-foreground",
day_hidden: "invisible",
month_caption: "flex justify-center items-center h-7",
caption_label: "text-sm font-medium",

Choose a reason for hiding this comment

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

This breaks the styling when calendar captionLayout is set to dropdown.
I had success with

Suggested change
caption_label: "text-sm font-medium",
caption_label:
props.captionLayout !== "label" ? "hidden" : "text-sm font-medium",

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: react-day-picker 9.0.0 release screws up Calendar component