2

Demo: https://codesandbox.io/s/agitated-euler-rep54

Click on any "click me to set ref". The popper correctly positions itself. Now start scrolling, and you'll see the popper doesn't stick to the ref.

If you move .popper to be a direct child of .scroll-body, it works.

<div id="app">
    <div class="scroll-body">
      <div v-for="n in 40">
          <span @click="setRef" class="ref">
            click me to set ref
          </span>
      </div>
    </div>
    <div ref="popper" class="popper">popper</div>
</div>

What popper option do I need to set to make it work?

Eric Guan
  • 15,474
  • 8
  • 50
  • 61

3 Answers3

2

You should avoid changing the reference after the instance has been created like state.elements.reference = newReference and instead create a fresh popper instance entirely. The reason is the scrollParents detection is done when the instance is created (or updated).

https://codesandbox.io/s/nifty-night-5vjfm

You can change the reference dynamically if you call .setOptions({}) after setting it though, but I would recommend the above instead.

atomiks
  • 684
  • 6
  • 11
  • Cool, I copied code from this github comment. It's probably not recommended, but it works. https://github.com/popperjs/popper-core/issues/538#issuecomment-596601887. I like your solution better, thanks. EDIT: haha.. just realized you were the one who suggested the original solution https://github.com/popperjs/popper-core/issues/538#issuecomment-362141790 – Eric Guan Mar 24 '20 at 02:49
1

If you put overflow-y: scroll; on #app, it will work the way you want. Overflow-y needs to be set on the parent for it to affect the child.

0

I have encounter this issue, in my case, I forget to set container overflow: auto.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
jellytran
  • 61
  • 1
  • 5