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

Tooltip/popover: Fix auto placement to use viewport #16152

Merged
merged 3 commits into from
Apr 27, 2015
Merged

Tooltip/popover: Fix auto placement to use viewport #16152

merged 3 commits into from
Apr 27, 2015

Conversation

jarthod
Copy link
Contributor

@jarthod jarthod commented Mar 25, 2015

Currently, auto placement is using the container dimensions (if provided) or the element's parent to determine where to open the tooltip:

var $container   = this.options.container ? $(this.options.container) : this.$element.parent()
var containerDim = this.getPosition($container)

This is quite broken in fact, because the parent element could be just a small div outside the element for example, leading in a totally random placement (placing the tooltip on top even if there's no room). And the container can also be outside of the viewport.

This fix simply uses the viewport instead, that's the purpose of the viewport actually, to position the tooltip.
So the auto placement should use it to find where there's more room.
By default this is body, which is good.

Currently, auto placement is using the container dimensions (if provided) or the element's parent to determine where to open the tooltip:
```javascript
var $container   = this.options.container ? $(this.options.container) : this.$element.parent()
var containerDim = this.getPosition($container)
```
This is quite broken in fact, because the parent element could be just a small div outside the element for example, leading in a totally random placement (placing the tooltip on top even if there's no room). And the container can also be outside of the viewport.

This fix simply uses the viewport instead, that's the purpose of the viewport actually, to position the tooltip.
So the auto placement should use it to find where there's more room.
By default this is body, which is good.
@twbs-savage
Copy link

Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED

Commit: 0e8e522
Build details: https://travis-ci.org/twbs-savage/bootstrap/builds/55829985

(Please note that this is a fully automated comment.)

@cvrebert
Copy link
Collaborator

If you could add a unit test to prevent future regressions, that would be greatly appreciated.

@cvrebert cvrebert added the js label Mar 25, 2015
@jarthod
Copy link
Contributor Author

jarthod commented Mar 25, 2015

Yep, I'll try fixing the sauce labs failing tests and add a new one ;)

@jarthod
Copy link
Contributor Author

jarthod commented Mar 29, 2015

Ok I've just added a non-regression unit test and fixed another one which was actually not testing anything and passing by pure luck.

Also, I see you actually had a lot of specs about the auto-placement feature mentioning the viewport, this is good and comforts me into thinking that the behaviour I fixed was the expected one.

The funny part is that all these specs currently passes because the viewport happen to also be the direct parent on these specs.

@twbs-savage
Copy link

Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED

Commit: df96c3e
Build details: https://travis-ci.org/twbs-savage/bootstrap/builds/56296669

(Please note that this is a fully automated comment.)

@cvrebert
Copy link
Collaborator

There seem to be some test failures in all versions of IE.

@jarthod
Copy link
Contributor Author

jarthod commented Mar 29, 2015

Yep, I'm trying to have a look a this but can't manage to get tests running on IE9 yet.

@twbs-savage
Copy link

Tests passed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: CONFIRMED

Commit: 5921724
Build details: https://travis-ci.org/twbs-savage/bootstrap/builds/56316146

(Please note that this is a fully automated comment.)

@jarthod
Copy link
Contributor Author

jarthod commented Mar 30, 2015

This is now fixed.

@fat
Copy link
Member

fat commented Apr 27, 2015

This looks safe to try to me, anything else on your end @cvrebert

@cvrebert
Copy link
Collaborator

@fat Nope.

fat added a commit that referenced this pull request Apr 27, 2015
Tooltip/popover: Fix auto placement to use viewport
@fat fat merged commit aa47989 into twbs:master Apr 27, 2015
@mdo mdo added this to the v3.3.5 milestone Apr 27, 2015
@cvrebert cvrebert mentioned this pull request Apr 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants