-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Feature : rtl mode (with options) #679
Conversation
- [x] Add a rtl option (default false) - [x] Set inlined style according to this option - [x] Add slider-rtl class to wrapper ( slider (slider-horizontal|slider-vertical) - [x] Fix css file according top this class - [x] Set rtl mode automatic according to dir="rtl"
[x] documentation updates to README file [x] examples within [/tpl/index.tpl](https://github.com/seiyria/bootstrap-slider/blob/master/tpl/index.tpl)
Definitely a good start, however:
|
OK, units test passed (and errors fixed) 2 questions
|
not set is a fine default since it's falsy. as for unit tests, you'd have to ask @rovolution specifically on what he'd like to see with unit tests. |
@@ -384,16 +384,23 @@ const windowIsDefined = (typeof window === "object"); | |||
this.options[optName] = val; | |||
} | |||
|
|||
// Check options.rtl | |||
if(this.options.rtl==='auto'){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative
if (this.options.rtl === null) {
this.options.rtl = window.getComputedStyle(this.element).direction === 'rtl';
}
@@ -829,6 +848,7 @@ const windowIsDefined = (typeof window === "object"); | |||
tooltip_split: false, | |||
handle: 'round', | |||
reversed: false, | |||
rtl: 'auto', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alt : rtl: null,
About 'default' : currently bool|string => string==='default' use dir='rtl'. But null!==false see 6dadef3#r94231462 Else, bout unit test : 2 solutions : add some rtl=true in some of existing tests, or add a new global test RtlOptionsSpec. Wait for @rovolution :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shnoulle Thanks for taking time to submit a PR! It looks great for the most part! I left some specific feedback in the code, so if you could take some time to incorporate that in, it would be much appreciated!
1) I would like to see some unit tests for this new option to validate that it effects the slider in the desired way based upon what value it is set to.
2) Go ahead and create a new spec file (something like RtlOptionsSpec
) to contain the tests for this particular feature.
@@ -1196,7 +1216,11 @@ const windowIsDefined = (typeof window === "object"); | |||
this.rangeHighlightElements[i].style.top = `${currentRange.start}%`; | |||
this.rangeHighlightElements[i].style.height = `${currentRange.size}%`; | |||
} else { | |||
this.rangeHighlightElements[i].style.left = `${currentRange.start}%`; | |||
if(this.options.rtl){ | |||
this.rangeHighlightElements[i].style.right = currentRange.start + "%"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rewrite this using an ES6 template string?
this.rangeHighlightElements[i].style.right = `${currentRange.start}%`;
if(this.options.rtl){ | ||
this.rangeHighlightElements[i].style.right = currentRange.start + "%"; | ||
} else { | ||
this.rangeHighlightElements[i].style.left = currentRange.start + "%"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rewrite this using an ES6 template string?
@@ -1209,7 +1233,7 @@ const windowIsDefined = (typeof window === "object"); | |||
if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) { | |||
|
|||
var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width'; | |||
var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : 'marginLeft'; | |||
var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : (this.options.rtl ? 'marginRight' : 'marginLeft'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of doing nested ternary (which is a little difficult to read), could you just re-write the assignment of this variable to use an if...else
?
var styleMargin;
if (this.options.orientation === 'vertical') {
styleMargin = 'marginTop';
}
else if (this.options.rtl) {
styleMargin = 'marginRight';
}
else {
styleMargin = 'marginLeft';
}
this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + 'px'; | ||
this.tickLabelContainer.style['marginTop'] = this.sliderElem.offsetWidth / 2 * -1 + 'px'; | ||
if(this.options.rtl){ | ||
this.tickLabels[i].style['marginRight'] = this.sliderElem.offsetWidth + 'px'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rewrite this using an ES6 template string?
if(this.options.rtl){ | ||
this.tickLabels[i].style['marginRight'] = this.sliderElem.offsetWidth + 'px'; | ||
}else{ | ||
this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + 'px'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rewrite this using an ES6 template string?
@@ -1299,15 +1327,15 @@ const windowIsDefined = (typeof window === "object"); | |||
if (this.options.orientation === 'vertical') { | |||
this._css(this.tooltip_min, 'margin-top', -this.tooltip_min.offsetHeight / 2 + 'px'); | |||
} else { | |||
this._css(this.tooltip_min, 'margin-left', -this.tooltip_min.offsetWidth / 2 + 'px'); | |||
this._css(this.tooltip_min, 'margin-'+this.stylePos, -this.tooltip_min.offsetWidth / 2 + 'px'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rewrite this using an ES6 template string?
`margin-${this.stylePos}`
} | ||
|
||
if (this.options.orientation === 'vertical') { | ||
this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px'); | ||
} else { | ||
this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px'); | ||
this._css(this.tooltip, 'margin-'+this.stylePos, -this.tooltip.offsetWidth / 2 + 'px'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rewrite this using an ES6 template string?
`margin-${this.stylePos}`
@@ -1279,13 +1307,13 @@ const windowIsDefined = (typeof window === "object"); | |||
if (this.options.orientation === 'vertical') { | |||
this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px'); | |||
} else { | |||
this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px'); | |||
this._css(this.tooltip, 'margin-'+this.stylePos, -this.tooltip.offsetWidth / 2 + 'px'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rewrite this using an ES6 template string?
`margin-${this.stylePos}`
@@ -1317,7 +1345,7 @@ const windowIsDefined = (typeof window === "object"); | |||
if (this.options.orientation === 'vertical') { | |||
this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px'); | |||
} else { | |||
this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px'); | |||
this._css(this.tooltip, 'margin-'+this.stylePos, -this.tooltip.offsetWidth / 2 + 'px'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rewrite this using an ES6 template string?
`margin-${this.stylePos}`
@@ -1804,7 +1851,7 @@ const windowIsDefined = (typeof window === "object"); | |||
_setTooltipPosition: function(){ | |||
var tooltips = [this.tooltip, this.tooltip_min, this.tooltip_max]; | |||
if (this.options.orientation === 'vertical'){ | |||
var tooltipPos = this.options.tooltip_position || 'right'; | |||
var tooltipPos = this.options.tooltip_position || (this.options.rtl ? 'left' : 'right'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you refactor this to an if..else
since the logic to determine the variable's value is a little more complex?
var tooltipPos;
if (this.options.tooltip_position) {
tooltipPos = this.options.tooltip_position;
}
else if (this.options.rtl) {
tooltipPos = 'left';
}
else {
tooltipPos = 'right';
}
@rovolution : thanks for reviewing :) 😃 . Maybe about RtlOptionsSpec i need your help after . I hope to work on it before end of the week :). And thanks a lot for this repo |
- [x] rewrite using ES6 template string - [x] refactor imbricated ternary test
- [x] RtlOptionsSpec unit test
Attention : using rtl : 'auto' by default update API (different behaviour in a rtl page) then can make it to false by default then don't break API |
expect(dirIsRtl).toBeTruthy(); | ||
}); | ||
|
||
it("slider use inversed left and right inline style", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great tests!!!!
Just pulled down and ran locally and everything works great! merging now. Thanks again for this awesome PR! Will be available in |
merged and published to NPM at |
Thanks to you :) |
Pull Requests
Feedback