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: typing of ButtonPrimitive ref #2

Closed
wants to merge 2 commits into from
Closed

Conversation

cahnory
Copy link
Owner

@cahnory cahnory commented Oct 19, 2023

  • add forwardConditionalRefs utility function
  • add composeRefs utility function

- add forwardConditionalRefs utility function
- add composeRefs utility function
@cahnory
Copy link
Owner Author

cahnory commented Oct 19, 2023

Here's how it was tested:

export const Test = () => {
  const unknownRef = useRef();
  const anchorRef = useRef<HTMLAnchorElement>();
  const buttonRef = useRef<HTMLButtonElement>();
  const bothRef = useRef<HTMLAnchorElement & HTMLButtonElement>();

  return (
    <>
      {/* Expected success */}
      <ButtonPrimitive />
      <ButtonPrimitive ref={undefined} />
      <ButtonPrimitive ref={buttonRef} />
      <ButtonPrimitive ref={unknownRef} />
      <ButtonPrimitive href="#" />
      <ButtonPrimitive href="#" ref={undefined} />
      <ButtonPrimitive href="#" ref={anchorRef} />
      <ButtonPrimitive href="#" ref={unknownRef} />


      {/* Would be better if it fails but success */}
      <ButtonPrimitive ref={bothRef} />
      <ButtonPrimitive href="#" ref={bothRef} />


      {/* Expected fails */}
      <ButtonPrimitive ref={anchorRef} />
      <ButtonPrimitive href="#" ref={buttonRef} />

      <ButtonPrimitive target="formId" />
      <ButtonPrimitive formTarget="formId" href="#" />
    </>
  );
};

Copy link

@QuentinLeFourbe QuentinLeFourbe left a comment

Choose a reason for hiding this comment

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

j'ai pas tout compris

@cahnory cahnory closed this Oct 21, 2023
@cahnory cahnory deleted the fix-button-primitive-ref branch November 2, 2023 17:22
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