Popping Out of Hidden Overflow

Viewed 26

I have items that are listed in a container with overflow-y-scroll and each item has a tooltip that needs to be displayed to the right of the list item but outside of the container.

I followed this article and managed to implement something similar with Tailwind. See Tailwind Play. The problem is that the tooltips positions are incorrect after scrolling. (I assume it's because the list item is static)

How can I make the tooltip move with the list item as it scrolls? Is there a better way to do this?

<script src="https://cdn.tailwindcss.com"></script>
<div class="flex h-screen items-center justify-center">
  <div class="relative">
    <ul class="h-24 w-24 space-y-3 overflow-y-auto overflow-x-hidden rounded-md border bg-gray-100 py-2 px-4">
      <li class="group static cursor-pointer">
        Item 1
        <div class="invisible absolute z-10 group-hover:visible">
          <p class="ml-14 -mt-6 w-20 rounded-lg bg-blue-500 px-2 py-1 text-sm text-white shadow">Tooltip 1</p>
        </div>
      </li>

      <li class="group static cursor-pointer">
        Item 2
        <div class="invisible absolute z-10 group-hover:visible">
          <p class="ml-14 -mt-6 w-20 rounded-lg bg-blue-500 px-2 py-1 text-sm text-white shadow">Tooltip 2</p>
        </div>
      </li>

      <li class="group static cursor-pointer">
        Item 3
        <div class="invisible absolute z-10 group-hover:visible">
          <p class="ml-14 -mt-6 w-20 rounded-lg bg-blue-500 px-2 py-1 text-sm text-white shadow">Tooltip 3</p>
        </div>
      </li>

      <li class="group static cursor-pointer">
        Item 4
        <div class="invisible absolute z-10 group-hover:visible">
          <p class="ml-14 -mt-6 w-20 rounded-lg bg-blue-500 px-2 py-1 text-sm text-white shadow">Tooltip 4</p>
        </div>
      </li>
    </ul>
  </div>
</div>

0 Answers
Related