Skip to content

Commit 64d556d

Browse files
authored
fix(carousel): disable the next/prev controls when the carousel is sliding (closes #4210) (#4212)
1 parent 7e4f160 commit 64d556d

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

Diff for: src/components/carousel/carousel.js

+32-14
Original file line numberDiff line numberDiff line change
@@ -498,19 +498,36 @@ export const BCarousel = /*#__PURE__*/ Vue.extend({
498498
// Prev and next controls
499499
let controls = h()
500500
if (this.controls) {
501+
const prevHandler = evt => {
502+
/* istanbul ignore next */
503+
if (!this.isSliding) {
504+
this.handleClick(evt, this.prev)
505+
} else {
506+
evt.preventDefault()
507+
}
508+
}
509+
const nextHandler = evt => {
510+
/* istanbul ignore next */
511+
if (!this.isSliding) {
512+
this.handleClick(evt, this.next)
513+
} else {
514+
evt.preventDefault()
515+
}
516+
}
501517
controls = [
502518
h(
503519
'a',
504520
{
505521
class: ['carousel-control-prev'],
506-
attrs: { href: '#', role: 'button', 'aria-controls': this.safeId('__BV_inner_') },
522+
attrs: {
523+
href: '#',
524+
role: 'button',
525+
'aria-controls': this.safeId('__BV_inner_'),
526+
'aria-disabled': this.isSliding ? 'true' : null
527+
},
507528
on: {
508-
click: evt => {
509-
this.handleClick(evt, this.prev)
510-
},
511-
keydown: evt => {
512-
this.handleClick(evt, this.prev)
513-
}
529+
click: prevHandler,
530+
keydown: prevHandler
514531
}
515532
},
516533
[
@@ -522,14 +539,15 @@ export const BCarousel = /*#__PURE__*/ Vue.extend({
522539
'a',
523540
{
524541
class: ['carousel-control-next'],
525-
attrs: { href: '#', role: 'button', 'aria-controls': this.safeId('__BV_inner_') },
542+
attrs: {
543+
href: '#',
544+
role: 'button',
545+
'aria-controls': this.safeId('__BV_inner_'),
546+
'aria-disabled': this.isSliding ? 'true' : null
547+
},
526548
on: {
527-
click: evt => {
528-
this.handleClick(evt, this.next)
529-
},
530-
keydown: evt => {
531-
this.handleClick(evt, this.next)
532-
}
549+
click: nextHandler,
550+
keydown: nextHandler
533551
}
534552
},
535553
[

0 commit comments

Comments
 (0)