Closed Spence1115 closed 1 year ago
@ycs77 I made a forked PR with a test to reproduce this bug https://github.com/ycs77/headlessui-float/pull/79
Solved my own issue, needed a forwardRef.
import { Listbox } from '@headlessui/react';
import { Float } from '@headlessui-float/react';
import React from 'react';
export default function App() {
type Option = {
label: string;
value: number;
};
interface SelectionOptionsProps {
options: Option[];
}
const SelectionOptions = React.forwardRef(
({ options }: SelectionOptionsProps, ref) => (
<Listbox.Options ref={ref}>
{options.map((option) => (
<Listbox.Option value={option}>{option.label}</Listbox.Option>
))}
</Listbox.Options>
)
);
const options = [
{
label: 'First',
value: 1,
},
{
label: 'Second',
value: 2,
},
];
return (
<>
<div>
<Listbox>
<Float>
<Listbox.Button>Dropdown failing here</Listbox.Button>
<SelectionOptions options={options} />
</Float>
</Listbox>
</div>
<div>
<Listbox>
<Float>
<Listbox.Button>Dropdown working here</Listbox.Button>
<Listbox.Options>
{options.map((option) => (
<Listbox.Option value={option}>{option.label}</Listbox.Option>
))}
</Listbox.Options>
</Float>
</Listbox>
</div>
</>
);
}
Use Version Use version when bugs appear:
@floating-ui/core
: v1.4.1@floating-ui/dom
: v1.2.9Describe the bug Using Listbox, if I extract the
Listbox.Options
into a reusable component, I get the following error when clicking on the button to open the dropdownError: Did you forget to passthrough the
refto the actual DOM node?
To Reproduce
https://stackblitz.com/edit/github-57al64?file=src%2FApp.tsx
Dropdown working here
Dropdown failing here
Expected behavior I should be able to extract the dropdown content into another component and it still work