Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Event type is lost when using as prop in React package  #337

Open
@kris-ellery

Description

Hi there! Thank you for working on a robust polymorphic component package with forwardRef support. I've been following the recent updates, including addition of react-polymorphed types. I noticed the event type gets lost when using as prop. It works in react-polymorphed, but not here. I was wondering if thats expected or a known issue?

react-polymorphed

import React, { forwardRef } from 'react';
import type { PolyRefFunction } from 'react-polymorphed';

const polyForwardRef = forwardRef as PolyRefFunction;

const PolyComponent = polyForwardRef<'div', {}>((props, ref) => {
    const { as: As = 'div', ...rest } = props;
    return <As ref={ref} {...rest} />;
});

const App = () => {
    return (
        <>
            {/* 🙂 event: React.MouseEvent<HTMLDivElement, MouseEvent> */}
            <PolyComponent onClick={(event) => console.log(event)} />
            {/* 🙂 event: React.MouseEvent<HTMLAnchorElement, MouseEvent> */}
            <PolyComponent as="a" onClick={(event) => console.log(event)} />
        </>
    );
};

@polymorphic-factory/react

import React from 'react';
import { polymorphicFactory } from '@polymorphic-factory/react';

const poly = polymorphicFactory();

const App = () => {
    return (
        <>
            {/* 🙂 event: React.MouseEvent<HTMLDivElement, MouseEvent> */}
            <poly.div onClick={(event) => console.log(event)} />
            {/* 😔 event: any */}
            <poly.div as="a" onClick={(event) => console.log(event)} />
        </>
    );
};

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions