headlessui-float icon indicating copy to clipboard operation
headlessui-float copied to clipboard

Set CSS variable for adaptive width instead of `width`

Open vincerubinetti opened this issue 1 year ago • 1 comments
trafficstars

For various reasons, I need to have portal on my <Float>, and I want the adaptiveWidth option to set the min-width on the dropdown instead of the width. It'd be cool if the package set a variable like --width, so we could use the trigger width however we want. Or, you could pass width: number as a render/slot prop for the Content component.

vincerubinetti avatar May 03 '24 23:05 vincerubinetti

For now, I'm working around this like this:

<ListboxOptions
  class="list"
  @vue:updated="
    ({ el }) => {
      if (el?.tagName !== 'UL') return;
      el.style.minWidth = el.style.width;
      el.style.width = '';
    }
  "
>

This is in Vue. In React I guess you'd attach a ref and set the style on that.

vincerubinetti avatar May 03 '24 23:05 vincerubinetti

Hi @vincerubinetti, I've added the width attribute option for adaptive-width in new version v0.14.0 to solve this problem, you can pass the attribute option for adaptive-width to change the width attribute name.

Below example change the width attribute to min-width:

Usage (React)

<Float adaptive-width={{ attribute: 'min-width' }}>

Usage (Vue)

<Float :adaptive-width="{ attribute: 'min-width' }">

ycs77 avatar May 24 '24 19:05 ycs77