mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-13 00:54:04 +02:00
Fix carousel buttons (#34266)
* test(carousel): add test to check if next/prev button work as intended * fix(carousel): merge passed config with instance config in carouselInterface
This commit is contained in:
@@ -498,7 +498,14 @@ class Carousel extends BaseComponent {
|
|||||||
static carouselInterface(element, config) {
|
static carouselInterface(element, config) {
|
||||||
const data = Carousel.getOrCreateInstance(element, config)
|
const data = Carousel.getOrCreateInstance(element, config)
|
||||||
|
|
||||||
const { _config } = data
|
let { _config } = data
|
||||||
|
if (typeof config === 'object') {
|
||||||
|
_config = {
|
||||||
|
..._config,
|
||||||
|
...config
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const action = typeof config === 'string' ? config : _config.slide
|
const action = typeof config === 'string' ? config : _config.slide
|
||||||
|
|
||||||
if (typeof config === 'number') {
|
if (typeof config === 'number') {
|
||||||
|
@@ -707,6 +707,34 @@ describe('Carousel', () => {
|
|||||||
|
|
||||||
carousel.next()
|
carousel.next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should call next()/prev() instance methods when clicking the respective direction buttons', () => {
|
||||||
|
fixtureEl.innerHTML = [
|
||||||
|
'<div id="carousel" class="carousel slide">',
|
||||||
|
' <div class="carousel-inner">',
|
||||||
|
' <div class="carousel-item active">item 1</div>',
|
||||||
|
' <div class="carousel-item">item 2</div>',
|
||||||
|
' <div class="carousel-item">item 3</div>',
|
||||||
|
' </div>',
|
||||||
|
' <button class="carousel-control-prev" type="button" data-bs-target="#carousel" data-bs-slide="prev"></button>',
|
||||||
|
' <button class="carousel-control-next" type="button" data-bs-target="#carousel" data-bs-slide="next"></button>',
|
||||||
|
'</div>'
|
||||||
|
].join('')
|
||||||
|
|
||||||
|
const carouselEl = fixtureEl.querySelector('#carousel')
|
||||||
|
const prevBtnEl = fixtureEl.querySelector('.carousel-control-prev')
|
||||||
|
const nextBtnEl = fixtureEl.querySelector('.carousel-control-next')
|
||||||
|
|
||||||
|
const carousel = new Carousel(carouselEl)
|
||||||
|
const nextSpy = spyOn(carousel, 'next')
|
||||||
|
const prevSpy = spyOn(carousel, 'prev')
|
||||||
|
|
||||||
|
nextBtnEl.click()
|
||||||
|
prevBtnEl.click()
|
||||||
|
|
||||||
|
expect(nextSpy).toHaveBeenCalled()
|
||||||
|
expect(prevSpy).toHaveBeenCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('nextWhenVisible', () => {
|
describe('nextWhenVisible', () => {
|
||||||
|
Reference in New Issue
Block a user