@@ -235,7 +235,11 @@ export class Range implements ComponentInterface {
235
235
const currentX = detail . currentX ;
236
236
237
237
// figure out which knob they started closer to
238
- const ratio = clamp ( 0 , ( currentX - rect . left ) / rect . width , 1 ) ;
238
+ let ratio = clamp ( 0 , ( currentX - rect . left ) / rect . width , 1 ) ;
239
+ if ( document . dir === 'rtl' ) {
240
+ ratio = 1 - ratio ;
241
+ }
242
+
239
243
this . pressedKnob =
240
244
! this . dualKnobs ||
241
245
Math . abs ( this . ratioA - ratio ) < Math . abs ( this . ratioB - ratio )
@@ -262,6 +266,10 @@ export class Range implements ComponentInterface {
262
266
// update the knob being interacted with
263
267
const rect = this . rect ;
264
268
let ratio = clamp ( 0 , ( currentX - rect . left ) / rect . width , 1 ) ;
269
+ if ( document . dir === 'rtl' ) {
270
+ ratio = 1 - ratio ;
271
+ }
272
+
265
273
if ( this . snaps ) {
266
274
// snaps the ratio to the current value
267
275
ratio = valueToRatio (
@@ -353,31 +361,56 @@ export class Range implements ComponentInterface {
353
361
render ( ) {
354
362
const { min, max, step, ratioLower, ratioUpper } = this ;
355
363
356
- const barL = `${ ratioLower * 100 } %` ;
357
- const barR = `${ 100 - ratioUpper * 100 } %` ;
364
+ const barStart = `${ ratioLower * 100 } %` ;
365
+ const barEnd = `${ 100 - ratioUpper * 100 } %` ;
366
+
367
+ const isRTL = document . dir === 'rtl' ;
368
+ const start = isRTL ? 'right' : 'left' ;
369
+ const end = isRTL ? 'left' : 'right' ;
358
370
359
371
const ticks = [ ] ;
360
372
if ( this . snaps ) {
361
373
for ( let value = min ; value <= max ; value += step ) {
362
374
const ratio = valueToRatio ( value , min , max ) ;
363
- ticks . push ( {
375
+
376
+ const tick : any = {
364
377
ratio,
365
378
active : ratio >= ratioLower && ratio <= ratioUpper ,
366
- left : `${ ratio * 100 } %`
367
- } ) ;
379
+ } ;
380
+
381
+ tick [ start ] = `${ ratio * 100 } %` ;
382
+
383
+ ticks . push ( tick ) ;
368
384
}
369
385
}
370
386
387
+ const tickStyle = ( tick : any ) => {
388
+ const style : any = { } ;
389
+
390
+ style [ start ] = tick [ start ] ;
391
+
392
+ return style ;
393
+ } ;
394
+
395
+ const barStyle = ( ) => {
396
+ const style : any = { } ;
397
+
398
+ style [ start ] = barStart ;
399
+ style [ end ] = barEnd ;
400
+
401
+ return style ;
402
+ } ;
403
+
371
404
return [
372
405
< slot name = "start" > </ slot > ,
373
406
< div class = "range-slider" ref = { el => this . rangeSlider = el } >
374
- { ticks . map ( t => (
407
+ { ticks . map ( tick => (
375
408
< div
376
- style = { { left : t . left } }
409
+ style = { tickStyle ( tick ) }
377
410
role = "presentation"
378
411
class = { {
379
412
'range-tick' : true ,
380
- 'range-tick-active' : t . active
413
+ 'range-tick-active' : tick . active
381
414
} }
382
415
/>
383
416
) ) }
@@ -386,10 +419,7 @@ export class Range implements ComponentInterface {
386
419
< div
387
420
class = "range-bar range-bar-active"
388
421
role = "presentation"
389
- style = { {
390
- left : barL ,
391
- right : barR
392
- } }
422
+ style = { barStyle ( ) }
393
423
/>
394
424
395
425
{ renderKnob ( {
@@ -435,6 +465,17 @@ interface RangeKnob {
435
465
}
436
466
437
467
function renderKnob ( { knob, value, ratio, min, max, disabled, pressed, pin, handleKeyboard } : RangeKnob ) {
468
+ const isRTL = document . dir === 'rtl' ;
469
+ const start = isRTL ? 'right' : 'left' ;
470
+
471
+ const knobStyle = ( ) => {
472
+ const style : any = { } ;
473
+
474
+ style [ start ] = `${ ratio * 100 } %` ;
475
+
476
+ return style ;
477
+ } ;
478
+
438
479
return (
439
480
< div
440
481
onKeyDown = { ( ev : KeyboardEvent ) => {
@@ -458,9 +499,7 @@ function renderKnob({ knob, value, ratio, min, max, disabled, pressed, pin, hand
458
499
'range-knob-min' : value === min ,
459
500
'range-knob-max' : value === max
460
501
} }
461
- style = { {
462
- 'left' : `${ ratio * 100 } %`
463
- } }
502
+ style = { knobStyle ( ) }
464
503
role = "slider"
465
504
tabindex = { disabled ? - 1 : 0 }
466
505
aria-valuemin = { min }
0 commit comments