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

[Bug v1.6.0] Popover doesn't receive Fragment as value of the 'as' prop #1430

Closed
alissaVrk opened this issue May 10, 2022 · 2 comments · Fixed by #1465
Closed

[Bug v1.6.0] Popover doesn't receive Fragment as value of the 'as' prop #1430

alissaVrk opened this issue May 10, 2022 · 2 comments · Fixed by #1465
Assignees

Comments

@alissaVrk
Copy link

What package within Headless UI are you using?
@headlessui/react

What version of that package are you using?
v1.6.0

What browser are you using?
Chrome

Reproduction URL
https://codesandbox.io/s/headless-ui-switch-forked-3oycet?file=/src/App.js

Describe your issue
Setting Fragment in the 'as' prop of the Popover worked in v1.5.0 and stopped working in v1.6.0, saying that you pass a ref to the Fragment.

This isn't very good, since there is no good reason for me to wrap a button with a div

I have a workaround, not a pretty one:

import { forwardRef, Children, Fragment } from 'react';

export const ForwardRefToFirstFragment = forwardRef(({ children, ...props }, ref) => {
  const [firstChild, ...rest] = Children.toArray(children);
  //@ts-ignore
  const childWithRef = cloneElement(firstChild, { ref });

  return (
    <Fragment {...props}>
      {childWithRef}
      {rest}
    </Fragment>
  );
});

<Popover as={ForwardRefToFirstFragment}>
        <Popover.Button>CLICK ME</Popover.Button>
        <Popover.Panel>this is our floating content</Popover.Panel>
</Popover>
@alissaVrk alissaVrk changed the title Popover doesn't receive Fragment as value of the 'as' prop Popover doesn't receive Fragment as value of the 'as' prop since v1.6.0 May 13, 2022
@alissaVrk alissaVrk changed the title Popover doesn't receive Fragment as value of the 'as' prop since v1.6.0 [Bug v1.6.0] Popover doesn't receive Fragment as value of the 'as' prop May 13, 2022
@RobinMalfait RobinMalfait self-assigned this May 18, 2022
@RobinMalfait
Copy link
Member

Hey! Thank you for your bug report!
Much appreciated! 🙏

This should be fixed by #1465, and will be available in the next release.

You can already try it using npm install @headlessui/react@insiders.

Here is an updated CodeSandbox with the latest insiders version: https://codesandbox.io/s/headless-ui-popover-with-fragment-forked-o9teuf?file=/src/App.js

@alissaVrk
Copy link
Author

amazing, thank you very much :)

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 a pull request may close this issue.

3 participants
@alissaVrk @RobinMalfait and others