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

Fix TypeScript error on Calendar component due to children #6334

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

Conversation

haydenbleasel
Copy link

Problem

react-day-picker's DayPicker component takes a property called components, which in turn we are passing IconLeft and IconRight. The properties for these two components takes children, which Radix's icons do not like since they're typed as SVG elements. As such, you end up with the following TS error:

Type '{ style?: CSSProperties | undefined; children?: ReactNode; className: any; }' is not assignable to type 'IconProps'.
  Types of property 'children' are incompatible.
    Type 'ReactNode' is not assignable to type 'undefined'.
      Type 'null' is not assignable to type 'undefined'.ts(2322)

Fix

This pull request includes changes to two Calendar components to ensure that the IconLeft and IconRight components destructure children from the props before spreading them on to Radix's icons. This change was applied to both the default and New York versions of the calendar.

Copy link

vercel bot commented Jan 12, 2025

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

A member of the Team first needs to authorize it.

@haydenbleasel haydenbleasel changed the title Remove children from calendar components Fix TypeScript error on Calendar component due to children Jan 12, 2025
haydenbleasel added a commit to haydenbleasel/next-forge that referenced this pull request Jan 12, 2025
haydenbleasel added a commit to haydenbleasel/next-forge that referenced this pull request Jan 12, 2025
* Scaffold Knock integration

* Misc fixes, regen lockfile

* Collab on Notifications (#388)

* update env vars

* update notif provider

* add secret key for server sdk

* create feed component

* make provider client

---------

Co-authored-by: Jeff Everhart <jeffeverhart383@gmail.com>

* Extract notifications into new package

* Update feed.tsx

* Move provider to package

* Scaffold doc

* Update env.ts

* change key and stub docs (#393)

* use public api key for feed

* stub out docs

* add link to keys docs

* Fix keys

* Add notifications feed to app

* Update notifications.mdx

* Temporary shadcn/ui patch

shadcn-ui/ui#6334

---------

Co-authored-by: Jeff Everhart <jeffeverhart383@gmail.com>
@@ -54,10 +54,10 @@ function Calendar({
...classNames,
}}
components={{
IconLeft: ({ className, ...props }) => (
IconLeft: ({ className, children, ...props }) => (

Choose a reason for hiding this comment

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

This approach might be misleading since children are destructured but not actually used anywhere.

Choose a reason for hiding this comment

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

Maybe try to explicitly type the IconLeft and IconRight like this:

type IconProps = React.SVGProps<SVGSVGElement> & {
  className?: string;
};

const IconLeft: FC<IconProps> = ({ className, ...props }) => (
  <ChevronLeft className={cn("h-4 w-4", className)} {...props} />
);

const IconRight: FC<IconProps> = ({ className, ...props }) => (
  <ChevronRight className={cn("h-4 w-4", className)} {...props} />
);

components={{
  IconLeft,
  IconRight,
}}
{...props}
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants