Skip to content

Commit

Permalink
Carousel: change class check as it can only exist if carousel is sliding
Browse files Browse the repository at this point in the history
Also, fix the corresponding test
  • Loading branch information
GeoSot authored and XhmikosR committed Mar 10, 2022
1 parent 3673933 commit 6e90434
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 1 addition & 2 deletions js/src/carousel.js
Expand Up @@ -59,7 +59,6 @@ const SELECTOR_ACTIVE = '.active'
const SELECTOR_ITEM = '.carousel-item'
const SELECTOR_ACTIVE_ITEM = SELECTOR_ACTIVE + SELECTOR_ITEM
const SELECTOR_ITEM_IMG = '.carousel-item img'
const SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev'
const SELECTOR_INDICATORS = '.carousel-indicators'
const SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]'
const SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]'
Expand Down Expand Up @@ -142,7 +141,7 @@ class Carousel extends BaseComponent {
this._stayPaused = true
}

if (SelectorEngine.findOne(SELECTOR_NEXT_PREV, this._element)) {
if (this._isSliding) {
triggerTransitionEnd(this._element)
this.cycle(true)
}
Expand Down
3 changes: 2 additions & 1 deletion js/tests/unit/carousel.spec.js
Expand Up @@ -868,7 +868,7 @@ describe('Carousel', () => {
})

describe('pause', () => {
it('should call cycle if the carousel have carousel-item-next and carousel-item-prev class', () => {
it('should call cycle if the carousel have carousel-item-next or carousel-item-prev class, cause is sliding', () => {
fixtureEl.innerHTML = [
'<div id="myCarousel" class="carousel slide">',
' <div class="carousel-inner">',
Expand All @@ -887,6 +887,7 @@ describe('Carousel', () => {
spyOn(carousel, 'cycle')
spyOn(carousel, '_clearInterval')

carousel._slide('next')
carousel.pause()

expect(carousel.cycle).toHaveBeenCalledWith(true)
Expand Down

0 comments on commit 6e90434

Please sign in to comment.