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

Prevent popovers from running off the screen #7700

Closed
ynicolaou opened this issue Apr 26, 2013 · 10 comments
Closed

Prevent popovers from running off the screen #7700

ynicolaou opened this issue Apr 26, 2013 · 10 comments

Comments

@ynicolaou
Copy link

I ran into the following issue when trying to use bootstrap's popover. The element that triggers the popover is close to the right border of the window, which causes the popover to extend off the screen.

image

I managed to fix this issue by adding the following piece of code, to where the positioning calculation is done:

if (tp.left + actualWidth > $(document).outerWidth()) {
    tp.left = ($(this.options.container).offset().left + $(this.options.container).outerWidth()) - actualWidth;
    $tip.children(".arrow").css("left", this.$element.offset().left - tp.left + (this.$element.width() / 2));
}

This seems to work for bottom and top placements. For left and right placements, you will need to use a slight variation:

if (tp.top < 0) {
    tp.top = $(this.options.container).offset().top;
    $tip.children(".arrow").css("top", this.$element.offset().top - tp.top + (this.$element.height() / 2));
}

Here is the end result, notice how the popover is now all contained inside the window:

image

I'm really interested in hearing opinions on whether this is the right fix for this issue. I would also like to see this being addressed in the next version of bootstrap.

@arielkirkwood
Copy link

Also interested in this issue!

@dperolio
Copy link

dperolio commented May 6, 2013

Ditto. Hulu has a good example of this done correctly.

Where did you put your code exactly? I've tried several spots that seem right, but it's not working for me. Thanks.

@eyot08
Copy link

eyot08 commented May 17, 2013

Same issue here, and also not sure where to insert that... didnt work for me.

@matthewblack
Copy link

+1

1 similar comment
@DeepAnchor
Copy link

+1

@arielkirkwood
Copy link

To those of you wondering where to put this, we actually monkey-patched the example code above inside bootstrap.js (the popover section, I think), so it's not a suitable workaround if you're using bootstrap.min.js (unless you do the minifying yourself)

@fat
Copy link
Member

fat commented Jul 18, 2013

pls refer to #1833

@fat fat closed this as completed Jul 18, 2013
@cstephe
Copy link

cstephe commented Apr 14, 2014

@fat I know this is closed more than 9 months now However, Isn't this bug a different issue than #1833.

Unless I'm reading it wrong #1833 deals with swapping positions if there is no room. Like top to bottom etc. This deals with for example a bottom tool tip on the right edge of the screen. There is room on the bottom but not to the right.

@cvrebert
Copy link
Collaborator

@cstephe Addressed by #12328 I believe.

@schartier
Copy link

+1

@twbs twbs locked and limited conversation to collaborators Oct 2, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants