mirror of
https://github.com/twbs/bootstrap.git
synced 2024-11-29 11:24:18 +01:00
Compare tooltip right offset to viewport right offset (and not width)
Closes #16142 by merging it.
This commit is contained in:
parent
d0926f2deb
commit
37a10d37c1
@ -764,6 +764,33 @@ $(function () {
|
||||
$styles.remove()
|
||||
})
|
||||
|
||||
QUnit.test('should not misplace the tip when the right edge offset is greater or equal than the viewport width', function (assert) {
|
||||
assert.expect(2)
|
||||
var styles = '<style>'
|
||||
+ '.tooltip, .tooltip *, .tooltip *:before, .tooltip *:after { box-sizing: border-box; }'
|
||||
+ '.tooltip, .tooltip .tooltip-inner { width: 50px; height: 50px; max-width: none; background: red; }'
|
||||
+ '.container-viewport { padding: 100px; margin-left: 100px; width: 100px; }'
|
||||
+ '</style>'
|
||||
var $styles = $(styles).appendTo('head')
|
||||
|
||||
var $container = $('<div class="container-viewport"/>').appendTo(document.body)
|
||||
var $target = $('<a href="#" rel="tooltip" title="tip">foobar</a>')
|
||||
.appendTo($container)
|
||||
.bootstrapTooltip({
|
||||
viewport: '.container-viewport'
|
||||
})
|
||||
|
||||
$target.bootstrapTooltip('show')
|
||||
var $tooltip = $container.find('.tooltip')
|
||||
assert.strictEqual(Math.round($tooltip.offset().left), Math.round($target.position().left + $target.width() / 2 - $tooltip[0].offsetWidth / 2))
|
||||
|
||||
$target.bootstrapTooltip('hide')
|
||||
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
|
||||
|
||||
$container.remove()
|
||||
$styles.remove()
|
||||
})
|
||||
|
||||
QUnit.test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function (assert) {
|
||||
assert.expect(1)
|
||||
var passed = true
|
||||
|
@ -378,7 +378,7 @@
|
||||
var rightEdgeOffset = pos.left + viewportPadding + actualWidth
|
||||
if (leftEdgeOffset < viewportDimensions.left) { // left overflow
|
||||
delta.left = viewportDimensions.left - leftEdgeOffset
|
||||
} else if (rightEdgeOffset > viewportDimensions.width) { // right overflow
|
||||
} else if (rightEdgeOffset > viewportDimensions.right) { // right overflow
|
||||
delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user