question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot center a popper on the screen

See original GitHub issue

CodePen demo

https://codepen.io/anon/pen/WyzXEB

Steps to reproduce the problem

  1. Go to the codepen and observe the box is not centered

What is the expected behavior?

I would expect an offset of 50vh and positionFixed: true to allow me to position a popper in the center of the screen, not attached to any specific element, but just attached to html or body.

What went wrong?

The offsets do not work reliably, and there seems to be no way to position a popper always fixed in the center of the screen.

Any other comments?

I really need support for centering a popper in the window, so I can finish converting Shepherd to use popper. Most of it works great, but it also needs to support showing a popper in the middle of the window centered horizontally and vertically, not attached to any elements.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
tminichcommented, Oct 29, 2020

In case someone needs this for Popper v2:

modifiers.push(<ComputeStylesModifier>{
    name: 'computeStyles',
    enabled: true,
    fn({state}) {
        state.styles.popper = {
            ...state.styles.popper,
            position: 'fixed',
            left: `${(window.innerWidth - state.rects.popper.width) / 2}px`,
            top: '50%',
            transform: 'translateY(-50%)',
        }

        return state
    },
})
1reaction
rwwagner90commented, Jul 12, 2018

We ended up using computeStyle for this and manually setting the styles.

computeStyle: {
  enabled: true,
  fn(data) {
    data.styles = Object.assign({}, data.styles, {
      left: '50%',
      top: '50%',
      transform: 'translate(-50%, -50%)'
    });

    return data;
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot center a popper on the screen · Issue #642 - GitHub
I really need support for centering a popper in the window, so I can finish converting Shepherd to use popper. Most of it...
Read more >
MUI Popper: Placement not working as intended when using ...
I have a Box and upon clicking it, I open a popper that has some inputs. I am using ref ...
Read more >
Everything I Know About Positioning Poppers (Tooltips ...
If it's positioned on the left, the text will be clipped and unable to be viewed, while on the right, it will cause...
Read more >
Prevent Overflow - Popper
The preventOverflow modifier prevents the popper from being cut off by moving it so that it stays visible within its boundary area. Don't...
Read more >
How to Build a Dynamically Positioned ... - Elegant Themes
Add Content to Popover Row · Button Alignment: center · Use Custom Styles for Button: YES · Button Border Width: 1px · Button...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found