-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Popper is not correctly placed by 1px
for some viewport widths in flexbox
container
#713
Comments
Maybe centering needs to use Edit: Actually I think the width of the popper should be computed. If it's an odd number of pixels wide, use const roundingFunc = popper.width % 2 === 0 ? Math.round : Math.floor
const offsets = {
left: roundingFunc(popper.left),
top: Math.round(popper.top),
bottom: Math.round(popper.bottom),
right: roundingFunc(popper.right)
}; Play here: https://codepen.io/anon/pen/Pxjdoo I'll add more tests |
Yep, it could be. In case |
Looks like the odd/even check doesn't fix it. This seems to work best, and preserves proper rounding for centering: const roundingFunc = data.placement.indexOf('-') > -1 ? Math.round : Math.floor |
It make sens that the width of popper don't apply in this scenario as we position to edge of reference element, when cantering it's a different story, IMHO this should resolve this issue Thanks for helping with this 👏 |
CodePen demo
https://codepen.io/anon/pen/WYOzLr
Steps to reproduce the problem
What is the expected behavior?
Popper should be placed pixel perfect to reference element
What went wrong?
For some viewport widths we got in
computeStyle
popper.left
very close to integer value, butMath.flor
in this case will break the offset by 1pxhttps://github.com/FezVrasta/popper.js/blob/master/packages/popper/src/modifiers/computeStyle.js#L44 changing it back to
Math.round
looks like fixes the problemAny other comments?
Connected with #277
The text was updated successfully, but these errors were encountered: