Skip to content

Typing error in morphing-popover #138

@euotiniel

Description

@euotiniel

When adding the morphing-popover component using the command:

npx motion-primitives@latest add morphing-popover

the 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

  1. Run npx motion-primitives@latest add morphing-popover in a React TypeScript project.
  2. Import and use the MorphingPopover component as documented.
  3. The typing error will occur during compilation.

Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions