tailwindlabs / headlessui

Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
https://headlessui.com
MIT License
26.28k stars 1.09k forks source link

Combobox aligns popover to the input element, making layouts that add elements around the input impossible #3515

Open WesSouza opened 1 month ago

WesSouza commented 1 month ago

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

2.1.9

What browser are you using?

N/A

Reproduction URL

https://codesandbox.io/p/devbox/headless-ui-combobox-layout-sqqh6f

Describe your issue

Some designs include elements around the text input of the combobox, such as selected options, a clear button and the popover indicator button.

HeadlessUI unfortunately hardcodes the floating reference to the input element, not allowing customization:

https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-react/src/components/combobox/combobox.tsx#L1053

let inputRef = useSyncRefs(
  internalInputRef,        // <-- <input>
  ref,
  useFloatingReference(),  // <-- The element the floating panel aligns with
  actions.setInputElement
)

This makes it very difficult to create this use case, requiring us to fill the component with the input, position everything absolutely, and constantly calculate the input padding based on the space used by the surrounding elements.

As a user, how would I like this to work?

Some options are available: