File tree 2 files changed +24
-16
lines changed
2 files changed +24
-16
lines changed Original file line number Diff line number Diff line change @@ -15,21 +15,21 @@ import
15
15
import s from '../../style.scss' ;
16
16
17
17
export default ( ) => (
18
- < CarouselProvider
19
- visibleSlides = { 2 }
20
- totalSlides = { 8 }
21
- step = { 1 }
22
- naturalSlideWidth = { 400 }
23
- naturalSlideHeight = { 500 }
24
- >
25
- < h2 className = { s . headline } > RTL</ h2 >
26
- < p >
18
+ < div dir = "rtl" >
19
+ < CarouselProvider
20
+ visibleSlides = { 2 }
21
+ totalSlides = { 8 }
22
+ step = { 1 }
23
+ naturalSlideWidth = { 400 }
24
+ naturalSlideHeight = { 500 }
25
+ >
26
+ < h2 className = { s . headline } > RTL</ h2 >
27
+ < p >
27
28
A carousel wrapped in an element with
28
- { ' ' }
29
- < code > dir="rtl"</ code >
29
+ { ' ' }
30
+ < code > dir="rtl"</ code >
30
31
, demonstrating support for use with right-to-left languages.
31
- </ p >
32
- < div dir = "rtl" >
32
+ </ p >
33
33
< Slider className = { s . slider } >
34
34
< Slide index = { 0 } >
35
35
< ImageWithZoom src = "./media/img01.jpeg" />
@@ -61,6 +61,6 @@ export default () => (
61
61
< ButtonNext > Next</ ButtonNext >
62
62
< ButtonLast > Last</ ButtonLast >
63
63
< DotGroup dotNumbers />
64
- </ div >
65
- </ CarouselProvider >
64
+ </ CarouselProvider >
65
+ </ div >
66
66
) ;
Original file line number Diff line number Diff line change @@ -201,6 +201,14 @@ const Slider = class Slider extends React.Component {
201
201
202
202
getSliderRef ( el ) {
203
203
this . sliderTrayElement = el ;
204
+ if ( el && window ) {
205
+ // NOTE: we can't rely on the element itself to detect direction
206
+ // as the direction of the slider is currently flipped to ltr
207
+ const carouselElement = el . closest ( '.carousel' ) ;
208
+ if ( carouselElement ) {
209
+ this . rtl = window . getComputedStyle ( carouselElement , null ) . getPropertyValue ( 'direction' ) === 'rtl' ;
210
+ }
211
+ }
204
212
}
205
213
206
214
@@ -234,7 +242,7 @@ const Slider = class Slider extends React.Component {
234
242
window . cancelAnimationFrame . call ( window , this . moveTimer ) ;
235
243
this . moveTimer = window . requestAnimationFrame . call ( window , ( ) => {
236
244
this . setState ( state => ( {
237
- deltaX : screenX - state . startX ,
245
+ deltaX : ( screenX - state . startX ) * ( this . rtl ? - 1 : 1 ) ,
238
246
deltaY : screenY - state . startY ,
239
247
preventingVerticalScroll : Math . abs ( screenY - state . startY )
240
248
<= this . props . verticalPixelThreshold
You can’t perform that action at this time.
0 commit comments