-
Notifications
You must be signed in to change notification settings - Fork 210
Open
Description
When adding the morphing-popover component using the command:
npx motion-primitives@latest add morphing-popoverthe generated code contains a typing error in the useClickOutside hook at line 182:
useClickOutside(ref, context.close);TypeScript throws the following error:
Argument of type 'RefObject<HTMLDivElement | null>' is not assignable to parameter of type 'RefObject<HTMLElement>'.
Type 'HTMLDivElement | null' is not assignable to type 'HTMLElement'.
Type 'null' is not assignable to type 'HTMLElement'.ts(2345)
const ref: RefObject<HTMLDivElement | null>This happens because RefObject<HTMLDivElement | null> is not directly compatible with RefObject<HTMLElement>, as null cannot be assigned to HTMLElement.
Steps to Reproduce
- Run
npx motion-primitives@latest add morphing-popoverin a React TypeScript project. - Import and use the MorphingPopover component as documented.
- The typing error will occur during compilation.
Possible Solution
A quick workaround is to use a type assertion:
useClickOutside(ref as React.RefObject<HTMLElement>, context.close);Alternatively, the typing of the useClickOutside hook could be adjusted to accept null in the RefObject definition.
I can submit a PR to fix this issue, ensuring compatibility with the expected typing and preventing new users from encountering this problem.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
