mirror of
https://github.com/wassname/slider.git
synced 2026-09-10 12:38:09 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b8e27e613 | ||
|
|
e438757a64 | ||
|
|
aad5fef20c | ||
|
|
1568019a59 | ||
|
|
abdb297c16 | ||
|
|
67b76953c6 | ||
|
|
b6d8f389ef |
+3
-3
@@ -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
@@ -228,7 +228,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
.rc-tooltip {
|
||||
.@{prefixClass}-tooltip {
|
||||
position: absolute;
|
||||
left: -9999px;
|
||||
top: -9999px;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rc-slider",
|
||||
"version": "4.0.1",
|
||||
"version": "5.1.0",
|
||||
"description": "slider ui component for react",
|
||||
"keywords": [
|
||||
"react",
|
||||
|
||||
+3
-1
@@ -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,
|
||||
|
||||
+15
-2
@@ -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,15 @@ class Slider extends React.Component {
|
||||
recent = bounds.length - 1;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' && (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 +125,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 +410,7 @@ class Slider extends React.Component {
|
||||
const {
|
||||
className,
|
||||
prefixCls,
|
||||
tooltipPrefixCls,
|
||||
disabled,
|
||||
vertical,
|
||||
dots,
|
||||
@@ -430,6 +441,7 @@ class Slider extends React.Component {
|
||||
|
||||
const commonHandleProps = {
|
||||
prefixCls,
|
||||
tooltipPrefixCls,
|
||||
noTip: isNoTip,
|
||||
tipTransitionName,
|
||||
tipFormatter,
|
||||
@@ -505,6 +517,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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user