From b85ca045e057d6f5982cc0cc9de4bfbf8b252a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Poupard?= Date: Fri, 11 Dec 2020 15:10:58 +0100 Subject: [PATCH] fix(carousel): switch prev/next directions in RTL --- js/src/carousel.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/js/src/carousel.js b/js/src/carousel.js index a266ec10f9..06a391419f 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -11,6 +11,7 @@ import { getElementFromSelector, getTransitionDurationFromElement, isVisible, + isRTL, reflow, triggerTransitionEnd, typeCheckConfig @@ -250,12 +251,20 @@ class Carousel extends BaseComponent { // swipe left if (direction > 0) { - this.prev() + if (isRTL) { + this.next() + } else { + this.prev() + } } // swipe right if (direction < 0) { - this.next() + if (isRTL) { + this.prev() + } else { + this.next() + } } } @@ -339,10 +348,18 @@ class Carousel extends BaseComponent { if (event.key === ARROW_LEFT_KEY) { event.preventDefault() - this.prev() + if (isRTL) { + this.next() + } else { + this.prev() + } } else if (event.key === ARROW_RIGHT_KEY) { event.preventDefault() - this.next() + if (isRTL) { + this.prev() + } else { + this.next() + } } }