Skip to content
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

fix position for reference node inside an iframe and popper outside #10

Open
yairEO opened this issue Dec 19, 2020 · 2 comments
Open

fix position for reference node inside an iframe and popper outside #10

yairEO opened this issue Dec 19, 2020 · 2 comments
Labels
feature request New feature or request

Comments

@yairEO
Copy link

yairEO commented Dec 19, 2020

reposition(
    /* reference: */ document.querySelector('.btn'),
    /* popper: */ document.querySelector('.dropdown'),
    /* We're using the default options */
)

I have situation where an element inside an iframe injects a popup outside of the iframe and shows it, and I need to position this popup near the element which triggered it, but nanopop cannot position it:

https://jsbin.com/duwohoz/2/edit?html,js,output

the click event data is unhelpful because it is relative to the iframe document, but I think nanopop can try and check if the reference element is inside an iframe (of course same-origin one) and if so, get the iframe position

In my demo above I show how to find the correct iframe which hosts the reference node and through that, find the iframes position on the parent document and now nanopop should theoretically detect all that and offset the position of the popper accordingly

Thanks for this awesome lightweight script!


This is for my open-source knobs project which is encapsulated inside an iframe but I am adding a color picker that should open outside (there's no visual space for it inside the iframe)

@yairEO yairEO changed the title Suggestion - position without a reference element Suggestion - fix position for reference node inside an iframe and popper outside Dec 19, 2020
@yairEO yairEO changed the title Suggestion - fix position for reference node inside an iframe and popper outside fix position for reference node inside an iframe and popper outside Dec 19, 2020
@yairEO
Copy link
Author

yairEO commented Dec 19, 2020

It would be good to add a third parameter, offset so I could manually adjust the popper element using my own calculations. Currently I am using the <iframe> element itself as the reference node, instead of the button due to the complexity mentioned.

I know I can manually adjust the top & left after the reposition fired, but it would be nice if I could do it in as few repaints as possible

@yairEO
Copy link
Author

yairEO commented Dec 19, 2020

Actually, it proves more difficult than I thought to get the offset of the button within the iframe:

https://jsbin.com/nopaciy/2/edit?css,js,output

getBoundingClientRect is not working as expected

@simonwep simonwep added the feature request New feature or request label Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants