react-popper
react-popper copied to clipboard
adaptive positioning with usePopper vertical position failing in certain circumstances
Reproduction demo
Run yarn install && yarn start
What went wrong?

I'm trying to make a gallery of images in buttons that shows a larger version of the image on hover. I'm running into these strange issues when using placement: 'top'. The tooltip shows fine when it is below the but not when it is above.
Trying changing placement, commenting in/out <Svg/> zooming in/out, scrolling. I can't narrow down exactly what is causing the problem, but it happens frequently, and in all browsers.
Packages versions
"@popperjs/core": "^2.4.4",
"react-popper": "^2.2.3",
It seems that this fixes it:
modifiers: [
{
name: 'computeStyles',
options: {
adaptive: false, // true by default
},
},
]
IMPORTANT EDIT
Also make sure you have <!DOCTYPE html> at the top of your pages as per this FAQ. I don't know if I missed this, or just ignored it because I couldn't see how that could possibly be the problem. But adding this actually let me avoid having to do the above options.
Possibly related to this issue on the popperjs core, except that I'm not even using position: relative.
Not sure if the same issue, but most likely it is.
I am using a rather complex combination but it seems it is a superset of what you have. I included some debug hints, so you may try those ...
What I have is
- React Tippy in headless mode with
inlinePositioningplugin (Tippy is based on Popper) - Default positioning:
top - Popper element rendered to
document.body flipmodifier withfallbackPlacements: ['top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end'],preventOverflowmodifier withmainAxis: false, altAxis: trueoffsetmodifier with dynamic offset calculation
What happens to me is that until the flip modifier kicks in, everything is OK

But once the flip modifier triggers the simulation of the alternative positions, it throws the popper element beyond the fold. Thanks to offset and some negative margins I can see it misplaced. Yours may be just below the fold ...

When I disable adaptive mode, it works OK and properly flips

After an agonizing debug session, I narrowed it down to a point where I found out that the popper element has both top: 0 and bottom: 0 set at the same time, making its height the window height instead of my default height and further calculating offsets with it

Upon further debugging, I found out that the initialStyles of the applyStyles modifier write top position but don't reset bottom getting the wrapper element into this situation. It seems that it is not aware of the historical styles applied by the flip modifier, or the flip modifier doesn't reset the complete state.

Hopefully someone with proper knowledge will pick this information up, and try to find a proper fix for it.
@FezVrasta for me also not working, do you have any update?
only strategy: fixed fixing it
@vincerubinetti why you closed? how you fixed?
Per my comment above, doctype fixes it. More of a strange consequence of browser quirks mode.
However, @hejtmii may want to keep this open for his more specific problem?
Okay just going to reopen for @hejtmii's situation. @happylolonly you probably need to upload a minimal reproduction for yours so they can fix it.
ok, I can do it little bit later, @FezVrasta do you need more info and possibilities to fix? I see you have new lib
👋 the library is in low maintenance mode, everyone should move to Floating UI and its React bindings.
https://github.com/floating-ui/react-popper#%EF%B8%8F-this-library-is-in-maintenance-mode
I don't plan to release additional versions unless they are meant to fix vulnerabilities. Hopefully that makes sense.