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.

Ability to place popper in a specific X, Y position

See original GitHub issue

I would like to implement a context menu using popper.js. I managed to do this using a reference element catching the contextmenu event. However I am wondering if it is possible to place the popper menu in a specific position.

In the case of a context menu the X and Y position would be given by the right click position.

Something like this:

var reference = document.querySelector('.my-button');
var popper = document.querySelector('.my-popper');

reference.addEventListener('contextmenu',
    function (e) {
        e.preventDefault();
        new Popper(reference, popper, {
            position: {
                x: e.clientX,
                y: e.clientY
            }
        })
    }
)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
tnrichcommented, Oct 6, 2018

For those coming after me, I think I got it to work by doing the following:

    const top = event.clientY;
    const right = event.clientX;
    const bottom = event.clientY;
    const left = event.clientX;
    const referenceObj = {
      getBoundingClientRect: () => ({
        top,
        right,
        bottom,
        left,

      }),
      clientWidth: 0,
      clientHeight: 0,
    }
0reactions
FezVrastacommented, Oct 8, 2018

@tnrich the interface is described at the bottom:

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to update the x/y position of a popper.js element?
what I have done here is to move your Popper() into a function called update popper, which will rebuild the popper new each...
Read more >
Everything I Know About Positioning Poppers (Tooltips ...
As an initial step, you'll place the popper somewhere next to the reference element somewhere in your UI. To do this, you'll choose...
Read more >
Placement option for both popper and target element? #226
Hi guys, I'm considering migrating my project to Popper from Tether (because Popper ... Offset modifier can take x and y offsets, use...
Read more >
How to Build a Dynamically Positioned Popover ... - YouTube
The popper.js library is a powerful positioning engine for tooltips and popovers. Today, we are going to harness the power of Popper.js in ......
Read more >
Popper (v2.×)
With Popper, you can place your elements anywhere and they will be positioned correctly, without needing to consider different screen sizes, layouts, etc....
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