diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 9b39acd3628a..9cb1438ca79a 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -221,7 +221,7 @@ const ScrollSpy = (($) => { return } - if (this._activeTarget && scrollTop < this._offsets[0]) { + if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) { this._activeTarget = null this._clear() return diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index a349b5337ee2..877ec67a2abf 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -287,6 +287,50 @@ $(function () { .scrollTop(201) }) + QUnit.test('should NOT clear selection if above the first section and first section is at the top', function (assert) { + assert.expect(4) + var done = assert.async() + + var sectionHTML = '
' + + '' + $(sectionHTML).appendTo('#qunit-fixture') + + var negativeHeight = -10 + var startOfSectionTwo = 101 + + var scrollspyHTML = '