diff --git a/js/src/carousel.js b/js/src/carousel.js index a5d5f143a497..27a8f7d3b82d 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -131,7 +131,9 @@ const Carousel = (($) => { nextWhenVisible() { // Don't call next when the page isn't visible - if (!document.hidden) { + // or the carousel or it's parent isn't visible + if (!document.hidden && + ($(this._element).is(':visible') && $(this._element).css('visibility') !== 'hidden')) { this.next() } } diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 894f78ab5139..b110fbd65d1c 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -842,4 +842,80 @@ $(function () { }) $textArea.trigger(eventKeyDown) }) + + QUnit.test('Should not go to the next item when the carousel is not visible', function (assert) { + assert.expect(2) + var done = assert.async() + var html = '