Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(range): RTL (from PR 17157) #17384

Merged
merged 37 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6b20d3b
Merge pull request #1 from ionic-team/master
abennouna Dec 14, 2018
af6b56a
Merge pull request #2 from ionic-team/master
abennouna Dec 20, 2018
ce0664d
Merge pull request #3 from ionic-team/master
abennouna Jan 3, 2019
d560010
Merge pull request #4 from ionic-team/master
abennouna Jan 8, 2019
6436971
Merge pull request #8 from ionic-team/master
abennouna Jan 8, 2019
b474223
Merge pull request #13 from ionic-team/master
abennouna Jan 9, 2019
4473bad
Merge pull request #16 from ionic-team/master
abennouna Jan 9, 2019
4920d4c
Merge pull request #19 from ionic-team/master
abennouna Jan 10, 2019
cd80b99
Merge pull request #21 from ionic-team/master
abennouna Jan 12, 2019
8d88990
Merge pull request #24 from ionic-team/master
abennouna Jan 15, 2019
25cde6f
Merge pull request #25 from ionic-team/master
abennouna Jan 15, 2019
294abf3
Merge pull request #27 from ionic-team/master
abennouna Jan 16, 2019
bcc306a
Merge pull request #30 from ionic-team/master
abennouna Jan 17, 2019
88043d5
Merge pull request #34 from ionic-team/master
abennouna Jan 18, 2019
a2e72f6
Merge pull request #36 from ionic-team/master
abennouna Jan 18, 2019
fd3e5ff
Merge pull request #38 from ionic-team/master
abennouna Jan 18, 2019
11e8db9
Merge pull request #41 from ionic-team/master
abennouna Jan 18, 2019
f0ed0f9
Merge pull request #42 from ionic-team/master
abennouna Jan 19, 2019
3a3857d
Merge pull request #44 from ionic-team/master
abennouna Jan 20, 2019
a312ca2
Merge pull request #46 from ionic-team/master
abennouna Jan 20, 2019
d75aef3
Merge pull request #48 from ionic-team/master
abennouna Jan 21, 2019
2f73c6e
Merge pull request #50 from ionic-team/master
abennouna Jan 22, 2019
3113807
Merge pull request #51 from ionic-team/master
abennouna Jan 23, 2019
00e039b
Merge pull request #52 from ionic-team/master
abennouna Jan 25, 2019
3d8cc72
Merge pull request #53 from ionic-team/master
abennouna Jan 26, 2019
91966f2
Merge pull request #55 from ionic-team/master
abennouna Jan 28, 2019
6df53f9
Merge pull request #57 from ionic-team/master
abennouna Feb 5, 2019
09d2b23
fix(range): implement RTL
Feb 5, 2019
8f36d8f
style(lint): use oneliners to turn off one-line rules
Feb 5, 2019
adddaa6
Merge branch 'master' into fix-range-rtl
abennouna Feb 5, 2019
00b47e2
Merge branch 'master' into fix-range-rtl
brandyscarney Feb 5, 2019
64cb572
Merge branch 'master' into fix-range-rtl
abennouna Feb 5, 2019
d6986c9
Merge branch 'master' into fix-range-rtl
abennouna Feb 6, 2019
17647fc
style(var): make variable more descriptive
Feb 6, 2019
34737d1
Merge branch 'master' into fix-range-rtl
abennouna Feb 7, 2019
8200383
Merge branch 'master' into fix-range-rtl
abennouna Feb 8, 2019
40482a1
Merge branch 'master' into fix-range-rtl
brandyscarney Feb 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/src/components/range/range.md.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
@include border-radius(50%, 50%, 50%, 0);
@include margin-horizontal(-13px, null);

@include rtl() {
/* stylelint-disable property-blacklist */
abennouna marked this conversation as resolved.
Show resolved Hide resolved
left: unset;
/* stylelint-enable property-blacklist */
}

position: absolute;

width: 26px;
Expand Down
19 changes: 19 additions & 0 deletions core/src/components/range/range.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
null
);

@include rtl() {
/* stylelint-disable property-blacklist */
left: unset;
/* stylelint-enable property-blacklist */
}

position: absolute;

width: var(--knob-handle-size);
Expand All @@ -95,6 +101,13 @@
.range-bar {
@include border-radius(var(--bar-border-radius));
@include position(calc((var(--height) - var(--bar-height)) / 2), null, null, 0);

@include rtl() {
/* stylelint-disable property-blacklist */
left: unset;
/* stylelint-enable property-blacklist */
}

position: absolute;

width: 100%;
Expand All @@ -113,6 +126,12 @@
calc(50% - var(--knob-size) / 2)
);

@include rtl() {
/* stylelint-disable property-blacklist */
left: unset;
/* stylelint-enable property-blacklist */
}

position: absolute;

width: var(--knob-size);
Expand Down
67 changes: 53 additions & 14 deletions core/src/components/range/range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ export class Range implements ComponentInterface {
const currentX = detail.currentX;

// figure out which knob they started closer to
const ratio = clamp(0, (currentX - rect.left) / rect.width, 1);
let ratio = clamp(0, (currentX - rect.left) / rect.width, 1);
if (document.dir === 'rtl') {
ratio = 1 - ratio;
}

this.pressedKnob =
!this.dualKnobs ||
Math.abs(this.ratioA - ratio) < Math.abs(this.ratioB - ratio)
Expand All @@ -262,6 +266,10 @@ export class Range implements ComponentInterface {
// update the knob being interacted with
const rect = this.rect;
let ratio = clamp(0, (currentX - rect.left) / rect.width, 1);
if (document.dir === 'rtl') {
ratio = 1 - ratio;
}

if (this.snaps) {
// snaps the ratio to the current value
ratio = valueToRatio(
Expand Down Expand Up @@ -353,27 +361,52 @@ export class Range implements ComponentInterface {
render() {
const { min, max, step, ratioLower, ratioUpper } = this;

const barL = `${ratioLower * 100}%`;
const barR = `${100 - ratioUpper * 100}%`;
const barStart = `${ratioLower * 100}%`;
const barEnd = `${100 - ratioUpper * 100}%`;

const isRTL = document.dir === 'rtl';
const start = isRTL ? 'right' : 'left';
const end = isRTL ? 'left' : 'right';

const ticks = [];
if (this.snaps) {
for (let value = min; value <= max; value += step) {
const ratio = valueToRatio(value, min, max);
ticks.push({

const t: any = {
ratio,
active: ratio >= ratioLower && ratio <= ratioUpper,
left: `${ratio * 100}%`
});
};

t[start] = `${ratio * 100}%`;

ticks.push(t);
}
}

const tickStyle = (t: any) => {
abennouna marked this conversation as resolved.
Show resolved Hide resolved
const style: any = {};

style[start] = t[start];

return style;
};

const barStyle = () => {
const style: any = {};

style[start] = barStart;
style[end] = barEnd;

return style;
};

return [
<slot name="start"></slot>,
<div class="range-slider" ref={el => this.rangeSlider = el}>
{ticks.map(t => (
<div
style={{ left: t.left }}
style={tickStyle(t)}
role="presentation"
class={{
'range-tick': true,
Expand All @@ -386,10 +419,7 @@ export class Range implements ComponentInterface {
<div
class="range-bar range-bar-active"
role="presentation"
style={{
left: barL,
right: barR
}}
style={barStyle()}
/>

{ renderKnob({
Expand Down Expand Up @@ -435,6 +465,17 @@ interface RangeKnob {
}

function renderKnob({ knob, value, ratio, min, max, disabled, pressed, pin, handleKeyboard }: RangeKnob) {
const isRTL = document.dir === 'rtl';
const start = isRTL ? 'right' : 'left';

const knobStyle = () => {
const style: any = {};

style[start] = `${ratio * 100}%`;

return style;
};

return (
<div
onKeyDown={(ev: KeyboardEvent) => {
Expand All @@ -458,9 +499,7 @@ function renderKnob({ knob, value, ratio, min, max, disabled, pressed, pin, hand
'range-knob-min': value === min,
'range-knob-max': value === max
}}
style={{
'left': `${ratio * 100}%`
}}
style={knobStyle()}
role="slider"
tabindex={disabled ? -1 : 0}
aria-valuemin={min}
Expand Down