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
hide popper when it scrolls outside of its boundaries #52
Comments
Yes probably we should add a "hide when reference is not visible" modifier (maybe with a shorter name ahah). If you create one please send a PR, it would be a nice addition! |
What is the best why to hide popper? I mean. With a modifier you just past |
I think the |
Hi, I'm not sure I have time to do the PR now. But this is what I did: I defined a modifier called /**
* Check if reference is visible inside boundaries
*
* @param {Object} data
* @param {Object} boundariesElement
* @return {Boolean}
*/
function isVisible(data, boundariesElement) {
const { boundaries, offsets } = data;
const { top, bottom } = offsets.reference;
const { height: boundariesHeight} = boundaries;
const boundariesOffsetTop = $(boundariesElement).offset().top;
const boundariesBottom = boundariesOffsetTop + boundariesHeight;
return ((top <= boundariesBottom) && (bottom >= boundariesOffsetTop));
}
/**
* Modifier to hide popper if is outside boundaries
* If boundaries is not defined we skip the check
*
* @param {Object} data
* @return {Object}
*/
const hideOnReferenceNotVisibleOnBoundaries = (data) => {
const boundariesElement = data.instance._options.boundariesElement;
if (boundariesElement === 'viewport') return data;
const visible = isVisible(data, boundariesElement);
// Hide popper
$(data.instance._popper).toggleClass('js-hide', !visible);
return data;
}; |
That's a bit too hacky to be included in Popper.js... Thanks anyway for your attempt. If someone else is interested please let me know. I can help with it. |
What's the hacky part? Just to improve my version :) |
We don't use jQuery with Popper.js, and modifiers should never access the DOM to write to it in any way. Your modifier should edit only the |
Ok, thanks @FezVrasta |
@andresgutgon check out #53, it should help with this modifier. |
I think we can close this one |
Why? The enhancement is not implemented yet |
I thought is a user decision to implement that. That you only provide the Of you want this modifier/whatever be in the core? |
I think it's a feature that would be nice to have in the core. |
I've implemented this feature in the function hide(data) {
var refRect = data.offsets.reference;
var bound = data.boundaries;
if (
refRect.bottom < bound.top ||
refRect.left > bound.right ||
refRect.top > bound.bottom ||
refRect.right < bound.left
) {
data.styles.display = 'none';
} else {
data.styles.display = '';
}
return data;
} |
I'm still seeing the popover after it scrolls outside of the boundaries. Is there anything I need to do to enable this feature? |
You have to enable it, it's disabled by default |
Cool. How would I enable it? I'm not quite sure I understand. Thanks! |
|
@FezVrasta https://popper.js.org/popper-documentation.html#modifiers..hide.enabled @ericsakmar you need to use something like .popper[x-out-of-boundaries] {
display: none;
} |
oh, right, thanks |
nvm, some kind of npm issue... works fine after refreshing node_modules 😄 |
Its not working properly @FezVrasta |
Hi, @FezVrasta, I tried using the modifier you suggested, and like @nmanikumar5, I am not able to get it to work either. |
For future readers, this is exactly what I added to get this to work (with v2 of popper):
I found that |
What is the expected behavior?
I would expect popper to disappear when element is not visible
Demo
To reproduce this you just need to change height on
.example2__scroll-box
from200%
to10000px
Solution
I'll try to do something with a custom modifier. But I think this should be fixed in the core.
The text was updated successfully, but these errors were encountered: