Compare commits

...
8 Commits
6 changed files with 50 additions and 8 deletions
+3 -3
View File
@@ -29,8 +29,8 @@ script:
env:
matrix:
- TEST_TYPE=lint
- TEST_TYPE=browser-test
- TEST_TYPE=browser-test-cover
- TEST_TYPE=test
- TEST_TYPE=coverage
- TEST_TYPE=saucelabs
global:
- secure: S1VwbaPzLnSH/IUT/wlJulxAX5VHRIDmSt53h/ycHcZsszUpWcLCJRQAe0fTVB2dAx5MdBbSZ+o+tr3tRwVB5TRAYm0oTCsYAkOZaWOB28RuUQtdGt3wf9xxTG1UiPiaLLUW3waX9zAaf3yqKBcJGf1op0RD8dksxbCFw/7xVbU=
@@ -39,4 +39,4 @@ env:
matrix:
allow_failures:
- env: "TEST_TYPE=saucelabs"
- env: "TEST_TYPE=saucelabs"
+1 -1
View File
@@ -228,7 +228,7 @@
}
}
.rc-tooltip {
.@{prefixClass}-tooltip {
position: absolute;
left: -9999px;
top: -9999px;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "rc-slider",
"version": "4.0.1",
"version": "5.1.1",
"description": "slider ui component for react",
"keywords": [
"react",
+3 -1
View File
@@ -25,6 +25,7 @@ export default class Handle extends React.Component {
render() {
const {
prefixCls,
tooltipPrefixCls,
className,
tipTransitionName,
tipFormatter,
@@ -51,7 +52,7 @@ export default class Handle extends React.Component {
const isTooltipVisible = dragging || this.state.isTooltipVisible;
return (
<Tooltip
prefixCls={prefixCls.replace('slider', 'tooltip')}
prefixCls={tooltipPrefixCls || `${prefixCls}-tooltip`}
placement="top"
visible={isTooltipVisible}
overlay={<span>{tipFormatter(value)}</span>}
@@ -66,6 +67,7 @@ export default class Handle extends React.Component {
Handle.propTypes = {
prefixCls: React.PropTypes.string,
tooltipPrefixCls: React.PropTypes.string,
className: React.PropTypes.string,
vertical: React.PropTypes.bool,
offset: React.PropTypes.number,
+17 -2
View File
@@ -5,6 +5,7 @@ import Track from './Track';
import DefaultHandle from './Handle';
import Steps from './Steps';
import Marks from './Marks';
import warning from 'warning';
function noop() {
}
@@ -30,7 +31,7 @@ class Slider extends React.Component {
constructor(props) {
super(props);
const { range, min, max } = props;
const { range, min, max, step } = props;
const initialValue = range ? Array.apply(null, Array(range + 1)).map(() => min) : min;
const defaultValue = ('defaultValue' in props ? props.defaultValue : initialValue);
const value = (props.value !== undefined ? props.value : defaultValue);
@@ -44,6 +45,17 @@ class Slider extends React.Component {
recent = bounds.length - 1;
}
if (process.env.NODE_ENV !== 'production' &&
step && Math.floor(step) === step &&
(max - min) % step !== 0) {
warning(
false,
'Slider[max] - Slider[min] (%s) should be a multiple of Slider[step] (%s)',
max - min,
step
);
}
this.state = {
handle: null,
recent,
@@ -115,7 +127,7 @@ class Slider extends React.Component {
const diffValue = diffPosition / this.getSliderLength() * (props.max - props.min);
const value = this.trimAlignValue(this.startValue + diffValue);
const oldValue = state[state.handle];
const oldValue = state.bounds[state.handle];
if (value === oldValue) return;
const nextBounds = [...state.bounds];
@@ -400,6 +412,7 @@ class Slider extends React.Component {
const {
className,
prefixCls,
tooltipPrefixCls,
disabled,
vertical,
dots,
@@ -430,6 +443,7 @@ class Slider extends React.Component {
const commonHandleProps = {
prefixCls,
tooltipPrefixCls,
noTip: isNoTip,
tipTransitionName,
tipFormatter,
@@ -505,6 +519,7 @@ Slider.propTypes = {
included: React.PropTypes.bool,
className: React.PropTypes.string,
prefixCls: React.PropTypes.string,
tooltipPrefixCls: React.PropTypes.string,
disabled: React.PropTypes.bool,
children: React.PropTypes.any,
onBeforeChange: React.PropTypes.func,
+25
View File
@@ -207,4 +207,29 @@ describe('rc-slider', function test() {
const slider = ReactDOM.render(<Slider vertical />, div);
expect(ReactTestUtils.scryRenderedDOMComponentsWithClass(slider, 'rc-slider-vertical').length).to.be(1);
});
it('should not call onChange when value is the same', () => {
const values = [];
const handler = (e) => {
values.push(e);
};
ReactDOM.render(<Slider onChange={handler}/>, div);
const handle = div.querySelector('.rc-slider-handle');
const down = document.createEvent('MouseEvent');
down.initEvent('mousedown', true, true);
const move = document.createEvent('MouseEvent');
move.initEvent('mousemove', true, true);
const up = document.createEvent('MouseEvent');
up.initEvent('mouseup', true, true);
handle.dispatchEvent(down);
handle.dispatchEvent(move);
handle.dispatchEvent(up);
expect(values.length).to.be(0);
});
});