mirror of
https://github.com/wassname/slider.git
synced 2026-09-11 12:42:49 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c021cadcbb | ||
|
|
4a59745a23 | ||
|
|
3e78e9ac4a | ||
|
|
82179e613a | ||
|
|
0a6fb5a570 | ||
|
|
53aa61faf2 | ||
|
|
9655483bf5 | ||
|
|
faa4f384a3 | ||
|
|
18ddbb796c | ||
|
|
051fef6603 | ||
|
|
b325daef48 | ||
|
|
db47c3d27d | ||
|
|
f20014a9d4 | ||
|
|
6074d5fc43 | ||
|
|
34754440ed | ||
|
|
fac5a1b9f3 | ||
|
|
1b8e27e613 | ||
|
|
e438757a64 | ||
|
|
aad5fef20c | ||
|
|
1568019a59 | ||
|
|
abdb297c16 | ||
|
|
67b76953c6 | ||
|
|
b6d8f389ef |
+2
-2
@@ -29,8 +29,8 @@ script:
|
|||||||
env:
|
env:
|
||||||
matrix:
|
matrix:
|
||||||
- TEST_TYPE=lint
|
- TEST_TYPE=lint
|
||||||
- TEST_TYPE=browser-test
|
- TEST_TYPE=test
|
||||||
- TEST_TYPE=browser-test-cover
|
- TEST_TYPE=coverage
|
||||||
- TEST_TYPE=saucelabs
|
- TEST_TYPE=saucelabs
|
||||||
global:
|
global:
|
||||||
- secure: S1VwbaPzLnSH/IUT/wlJulxAX5VHRIDmSt53h/ycHcZsszUpWcLCJRQAe0fTVB2dAx5MdBbSZ+o+tr3tRwVB5TRAYm0oTCsYAkOZaWOB28RuUQtdGt3wf9xxTG1UiPiaLLUW3waX9zAaf3yqKBcJGf1op0RD8dksxbCFw/7xVbU=
|
- secure: S1VwbaPzLnSH/IUT/wlJulxAX5VHRIDmSt53h/ycHcZsszUpWcLCJRQAe0fTVB2dAx5MdBbSZ+o+tr3tRwVB5TRAYm0oTCsYAkOZaWOB28RuUQtdGt3wf9xxTG1UiPiaLLUW3waX9zAaf3yqKBcJGf1op0RD8dksxbCFw/7xVbU=
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
# History
|
# History
|
||||||
----
|
----
|
||||||
|
|
||||||
|
## 5.0.0 / 2016-09-12
|
||||||
|
|
||||||
|
[#147](https://github.com/react-component/slider/issues/147) fix style conflicts with rc-tooltip [@benjycui](https://github.com/benjycui)
|
||||||
|
[#145](https://github.com/react-component/slider/pull/145) fix `onChange` will be triggered while mousemove [@Fuzzyma](https://github.com/Fuzzyma)
|
||||||
|
|
||||||
## 4.0.0 / 2016-08-12
|
## 4.0.0 / 2016-08-12
|
||||||
|
|
||||||
[#133](https://github.com/react-component/slider/pull/133) support multi-range ([@sosz](https://github.com/sosz))
|
[#133](https://github.com/react-component/slider/pull/133) support multi-range ([@sosz](https://github.com/sosz))
|
||||||
|
|||||||
+21
-8
@@ -23,13 +23,19 @@
|
|||||||
|
|
||||||
.@{prefixClass} {
|
.@{prefixClass} {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 4px;
|
height: 14px;
|
||||||
|
padding: 5px 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: @border-radius-base;
|
border-radius: @border-radius-base;
|
||||||
background-color: #e9e9e9;
|
|
||||||
|
|
||||||
.borderBox();
|
.borderBox();
|
||||||
|
|
||||||
|
&-rail {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
background-color: #e9e9e9;
|
||||||
|
height: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
&-track {
|
&-track {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
@@ -62,7 +68,7 @@
|
|||||||
|
|
||||||
&-mark {
|
&-mark {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 18px;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@@ -130,23 +136,30 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.@{prefixClass}-vertical {
|
.@{prefixClass}-vertical {
|
||||||
width: 4px;
|
width: 14px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
padding: 0 5px;
|
||||||
|
|
||||||
.@{prefixClass} {
|
.@{prefixClass} {
|
||||||
|
&-rail {
|
||||||
|
height: 100%;
|
||||||
|
width: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
&-track {
|
&-track {
|
||||||
|
left: 5px;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
width: 4px;
|
width: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-handle {
|
&-handle {
|
||||||
position: absolute;
|
|
||||||
margin-left: -5px;
|
margin-left: -5px;
|
||||||
margin-bottom: -7px;
|
margin-bottom: -7px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-mark {
|
&-mark {
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 10px;
|
left: 18px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +241,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.rc-tooltip {
|
.@{prefixClass}-tooltip {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: -9999px;
|
left: -9999px;
|
||||||
top: -9999px;
|
top: -9999px;
|
||||||
|
|||||||
+13
-10
@@ -18,16 +18,19 @@ const handleStyle = {
|
|||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
};
|
};
|
||||||
|
|
||||||
const CustomHandle = props => {
|
const CustomHandle = React.createClass({
|
||||||
const style = Object.assign({ left: `${props.offset}%` }, handleStyle);
|
propTypes: {
|
||||||
return (
|
value: React.PropTypes.any,
|
||||||
<div style={style}>val: {props.value}</div>
|
offset: React.PropTypes.number,
|
||||||
);
|
},
|
||||||
};
|
render() {
|
||||||
CustomHandle.propTypes = {
|
const props = this.props;
|
||||||
value: React.PropTypes.any,
|
const style = Object.assign({ left: `${props.offset}%` }, handleStyle);
|
||||||
offset: React.PropTypes.number,
|
return (
|
||||||
};
|
<div style={style}>val: {props.value}</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
+6
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rc-slider",
|
"name": "rc-slider",
|
||||||
"version": "4.0.1",
|
"version": "5.3.5",
|
||||||
"description": "slider ui component for react",
|
"description": "slider ui component for react",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"react",
|
"react",
|
||||||
@@ -19,10 +19,14 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"assets/*.css",
|
"assets/*.css",
|
||||||
"lib"
|
"lib",
|
||||||
|
"dist"
|
||||||
],
|
],
|
||||||
"licenses": "MIT",
|
"licenses": "MIT",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
|
"entry": {
|
||||||
|
"rc-slider": ["./assets/index.less", "./src/index.js"]
|
||||||
|
},
|
||||||
"style": "./assets/index.css",
|
"style": "./assets/index.css",
|
||||||
"config": {
|
"config": {
|
||||||
"port": 8005
|
"port": 8005
|
||||||
|
|||||||
+3
-1
@@ -25,6 +25,7 @@ export default class Handle extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
prefixCls,
|
prefixCls,
|
||||||
|
tooltipPrefixCls,
|
||||||
className,
|
className,
|
||||||
tipTransitionName,
|
tipTransitionName,
|
||||||
tipFormatter,
|
tipFormatter,
|
||||||
@@ -51,7 +52,7 @@ export default class Handle extends React.Component {
|
|||||||
const isTooltipVisible = dragging || this.state.isTooltipVisible;
|
const isTooltipVisible = dragging || this.state.isTooltipVisible;
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
prefixCls={prefixCls.replace('slider', 'tooltip')}
|
prefixCls={tooltipPrefixCls || `${prefixCls}-tooltip`}
|
||||||
placement="top"
|
placement="top"
|
||||||
visible={isTooltipVisible}
|
visible={isTooltipVisible}
|
||||||
overlay={<span>{tipFormatter(value)}</span>}
|
overlay={<span>{tipFormatter(value)}</span>}
|
||||||
@@ -66,6 +67,7 @@ export default class Handle extends React.Component {
|
|||||||
|
|
||||||
Handle.propTypes = {
|
Handle.propTypes = {
|
||||||
prefixCls: React.PropTypes.string,
|
prefixCls: React.PropTypes.string,
|
||||||
|
tooltipPrefixCls: React.PropTypes.string,
|
||||||
className: React.PropTypes.string,
|
className: React.PropTypes.string,
|
||||||
vertical: React.PropTypes.bool,
|
vertical: React.PropTypes.bool,
|
||||||
offset: React.PropTypes.number,
|
offset: React.PropTypes.number,
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ const Marks = ({ className, vertical, marks, included, upperBound, lowerBound, m
|
|||||||
|
|
||||||
const bottomStyle = {
|
const bottomStyle = {
|
||||||
// height: markWidth + '%',
|
// height: markWidth + '%',
|
||||||
marginBottom: '-200%',
|
marginBottom: '-50%',
|
||||||
bottom: `${(point - min) / range * 100}%`,
|
bottom: `${(point - min) / range * 100}%`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+56
-8
@@ -1,3 +1,4 @@
|
|||||||
|
import { findDOMNode } from 'react-dom';
|
||||||
import React, { cloneElement } from 'react';
|
import React, { cloneElement } from 'react';
|
||||||
import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
@@ -5,6 +6,7 @@ import Track from './Track';
|
|||||||
import DefaultHandle from './Handle';
|
import DefaultHandle from './Handle';
|
||||||
import Steps from './Steps';
|
import Steps from './Steps';
|
||||||
import Marks from './Marks';
|
import Marks from './Marks';
|
||||||
|
import warning from 'warning';
|
||||||
|
|
||||||
function noop() {
|
function noop() {
|
||||||
}
|
}
|
||||||
@@ -21,6 +23,13 @@ function getMousePosition(vertical, e) {
|
|||||||
return vertical ? e.clientY : e.pageX;
|
return vertical ? e.clientY : e.pageX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getHandleCenterPosition(vertical, handle) {
|
||||||
|
const coords = handle.getBoundingClientRect();
|
||||||
|
return vertical ?
|
||||||
|
coords.top + (coords.height * 0.5) :
|
||||||
|
coords.left + (coords.width * 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
function pauseEvent(e) {
|
function pauseEvent(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -30,7 +39,7 @@ class Slider extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(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 initialValue = range ? Array.apply(null, Array(range + 1)).map(() => min) : min;
|
||||||
const defaultValue = ('defaultValue' in props ? props.defaultValue : initialValue);
|
const defaultValue = ('defaultValue' in props ? props.defaultValue : initialValue);
|
||||||
const value = (props.value !== undefined ? props.value : defaultValue);
|
const value = (props.value !== undefined ? props.value : defaultValue);
|
||||||
@@ -44,6 +53,17 @@ class Slider extends React.Component {
|
|||||||
recent = bounds.length - 1;
|
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 = {
|
this.state = {
|
||||||
handle: null,
|
handle: null,
|
||||||
recent,
|
recent,
|
||||||
@@ -81,7 +101,7 @@ class Slider extends React.Component {
|
|||||||
const isNotControlled = !('value' in props);
|
const isNotControlled = !('value' in props);
|
||||||
if (isNotControlled) {
|
if (isNotControlled) {
|
||||||
this.setState(state);
|
this.setState(state);
|
||||||
} else if (state.handle) {
|
} else if (state.handle !== undefined) {
|
||||||
this.setState({ handle: state.handle });
|
this.setState({ handle: state.handle });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +112,7 @@ class Slider extends React.Component {
|
|||||||
|
|
||||||
onMouseMove(e) {
|
onMouseMove(e) {
|
||||||
const position = getMousePosition(this.props.vertical, e);
|
const position = getMousePosition(this.props.vertical, e);
|
||||||
this.onMove(e, position);
|
this.onMove(e, position - this.dragOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
onTouchMove(e) {
|
onTouchMove(e) {
|
||||||
@@ -102,7 +122,7 @@ class Slider extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const position = getTouchPosition(this.props.vertical, e);
|
const position = getTouchPosition(this.props.vertical, e);
|
||||||
this.onMove(e, position);
|
this.onMove(e, position - this.dragOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMove(e, position) {
|
onMove(e, position) {
|
||||||
@@ -115,7 +135,7 @@ class Slider extends React.Component {
|
|||||||
const diffValue = diffPosition / this.getSliderLength() * (props.max - props.min);
|
const diffValue = diffPosition / this.getSliderLength() * (props.max - props.min);
|
||||||
|
|
||||||
const value = this.trimAlignValue(this.startValue + diffValue);
|
const value = this.trimAlignValue(this.startValue + diffValue);
|
||||||
const oldValue = state[state.handle];
|
const oldValue = state.bounds[state.handle];
|
||||||
if (value === oldValue) return;
|
if (value === oldValue) return;
|
||||||
|
|
||||||
const nextBounds = [...state.bounds];
|
const nextBounds = [...state.bounds];
|
||||||
@@ -137,7 +157,14 @@ class Slider extends React.Component {
|
|||||||
onTouchStart(e) {
|
onTouchStart(e) {
|
||||||
if (isNotTouchEvent(e)) return;
|
if (isNotTouchEvent(e)) return;
|
||||||
|
|
||||||
const position = getTouchPosition(this.props.vertical, e);
|
let position = getTouchPosition(this.props.vertical, e);
|
||||||
|
if (!this.isEventFromHandle(e)) {
|
||||||
|
this.dragOffset = 0;
|
||||||
|
} else {
|
||||||
|
const handlePosition = getHandleCenterPosition(this.props.vertical, e.target);
|
||||||
|
this.dragOffset = position - handlePosition;
|
||||||
|
position = handlePosition;
|
||||||
|
}
|
||||||
this.onStart(position);
|
this.onStart(position);
|
||||||
this.addDocumentEvents('touch');
|
this.addDocumentEvents('touch');
|
||||||
pauseEvent(e);
|
pauseEvent(e);
|
||||||
@@ -145,7 +172,15 @@ class Slider extends React.Component {
|
|||||||
|
|
||||||
onMouseDown(e) {
|
onMouseDown(e) {
|
||||||
if (e.button !== 0) { return; }
|
if (e.button !== 0) { return; }
|
||||||
const position = getMousePosition(this.props.vertical, e);
|
|
||||||
|
let position = getMousePosition(this.props.vertical, e);
|
||||||
|
if (!this.isEventFromHandle(e)) {
|
||||||
|
this.dragOffset = 0;
|
||||||
|
} else {
|
||||||
|
const handlePosition = getHandleCenterPosition(this.props.vertical, e.target);
|
||||||
|
this.dragOffset = position - handlePosition;
|
||||||
|
position = handlePosition;
|
||||||
|
}
|
||||||
this.onStart(position);
|
this.onStart(position);
|
||||||
this.addDocumentEvents('mouse');
|
this.addDocumentEvents('mouse');
|
||||||
pauseEvent(e);
|
pauseEvent(e);
|
||||||
@@ -247,6 +282,13 @@ class Slider extends React.Component {
|
|||||||
return this._getPointsCache.points;
|
return this._getPointsCache.points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isEventFromHandle(e) {
|
||||||
|
return this.state.bounds.some((x, i) => (
|
||||||
|
this.refs[`handle-${i}`] &&
|
||||||
|
e.target === findDOMNode(this.refs[`handle-${i}`])
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
isValueOutOfBounds(value, props) {
|
isValueOutOfBounds(value, props) {
|
||||||
return value < props.min || value > props.max;
|
return value < props.min || value > props.max;
|
||||||
}
|
}
|
||||||
@@ -400,6 +442,7 @@ class Slider extends React.Component {
|
|||||||
const {
|
const {
|
||||||
className,
|
className,
|
||||||
prefixCls,
|
prefixCls,
|
||||||
|
tooltipPrefixCls,
|
||||||
disabled,
|
disabled,
|
||||||
vertical,
|
vertical,
|
||||||
dots,
|
dots,
|
||||||
@@ -430,6 +473,7 @@ class Slider extends React.Component {
|
|||||||
|
|
||||||
const commonHandleProps = {
|
const commonHandleProps = {
|
||||||
prefixCls,
|
prefixCls,
|
||||||
|
tooltipPrefixCls,
|
||||||
noTip: isNoTip,
|
noTip: isNoTip,
|
||||||
tipTransitionName,
|
tipTransitionName,
|
||||||
tipFormatter,
|
tipFormatter,
|
||||||
@@ -443,6 +487,7 @@ class Slider extends React.Component {
|
|||||||
offset: offsets[i],
|
offset: offsets[i],
|
||||||
dragging: handle === i,
|
dragging: handle === i,
|
||||||
key: i,
|
key: i,
|
||||||
|
ref: `handle-${i}`,
|
||||||
}));
|
}));
|
||||||
if (!range) { handles.shift(); }
|
if (!range) { handles.shift(); }
|
||||||
|
|
||||||
@@ -463,9 +508,10 @@ class Slider extends React.Component {
|
|||||||
|
|
||||||
const sliderClassName = classNames({
|
const sliderClassName = classNames({
|
||||||
[prefixCls]: true,
|
[prefixCls]: true,
|
||||||
|
[`${prefixCls}-with-marks`]: Object.keys(marks).length,
|
||||||
[`${prefixCls}-disabled`]: disabled,
|
[`${prefixCls}-disabled`]: disabled,
|
||||||
[className]: !!className,
|
|
||||||
[`${prefixCls}-vertical`]: this.props.vertical,
|
[`${prefixCls}-vertical`]: this.props.vertical,
|
||||||
|
[className]: !!className,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -473,6 +519,7 @@ class Slider extends React.Component {
|
|||||||
onTouchStart={disabled ? noop : this.onTouchStart.bind(this)}
|
onTouchStart={disabled ? noop : this.onTouchStart.bind(this)}
|
||||||
onMouseDown={disabled ? noop : this.onMouseDown.bind(this)}
|
onMouseDown={disabled ? noop : this.onMouseDown.bind(this)}
|
||||||
>
|
>
|
||||||
|
<div className={`${prefixCls}-rail`} />
|
||||||
{tracks}
|
{tracks}
|
||||||
<Steps prefixCls={prefixCls} vertical = {vertical} marks={marks} dots={dots} step={step}
|
<Steps prefixCls={prefixCls} vertical = {vertical} marks={marks} dots={dots} step={step}
|
||||||
included={isIncluded} lowerBound={bounds[0]}
|
included={isIncluded} lowerBound={bounds[0]}
|
||||||
@@ -505,6 +552,7 @@ Slider.propTypes = {
|
|||||||
included: React.PropTypes.bool,
|
included: React.PropTypes.bool,
|
||||||
className: React.PropTypes.string,
|
className: React.PropTypes.string,
|
||||||
prefixCls: React.PropTypes.string,
|
prefixCls: React.PropTypes.string,
|
||||||
|
tooltipPrefixCls: React.PropTypes.string,
|
||||||
disabled: React.PropTypes.bool,
|
disabled: React.PropTypes.bool,
|
||||||
children: React.PropTypes.any,
|
children: React.PropTypes.any,
|
||||||
onBeforeChange: React.PropTypes.func,
|
onBeforeChange: React.PropTypes.func,
|
||||||
|
|||||||
+133
@@ -5,6 +5,18 @@ const ReactDOM = require('react-dom');
|
|||||||
const ReactTestUtils = require('react-addons-test-utils');
|
const ReactTestUtils = require('react-addons-test-utils');
|
||||||
const Slider = require('..');
|
const Slider = require('..');
|
||||||
|
|
||||||
|
function createSliderWrapperComponent() {
|
||||||
|
return class SliderWrapper extends React.Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div style={{ position: `absolute`, width: `100px`, height: `10px` }}>
|
||||||
|
<Slider ref="slider"/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
require('../assets/index.less');
|
require('../assets/index.less');
|
||||||
|
|
||||||
describe('rc-slider', function test() {
|
describe('rc-slider', function test() {
|
||||||
@@ -207,4 +219,125 @@ describe('rc-slider', function test() {
|
|||||||
const slider = ReactDOM.render(<Slider vertical />, div);
|
const slider = ReactDOM.render(<Slider vertical />, div);
|
||||||
expect(ReactTestUtils.scryRenderedDOMComponentsWithClass(slider, 'rc-slider-vertical').length).to.be(1);
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set `dragOffset` to correct value when the left handle is clicked off-center', () => {
|
||||||
|
const slider = ReactDOM.render(<Slider />, div);
|
||||||
|
const leftHandle = ReactTestUtils.scryRenderedDOMComponentsWithClass(slider, 'rc-slider-handle')[0];
|
||||||
|
slider.onMouseDown({
|
||||||
|
type: 'mousedown',
|
||||||
|
target: leftHandle,
|
||||||
|
pageX: 5, button: 0,
|
||||||
|
stopPropagation() {},
|
||||||
|
preventDefault() {},
|
||||||
|
});
|
||||||
|
expect(slider.dragOffset).to.be(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should respect `dragOffset` while dragging the handle via MouseEvents', () => {
|
||||||
|
const SliderWrapper = createSliderWrapperComponent();
|
||||||
|
const slider = ReactDOM.render(<SliderWrapper/>, div).refs.slider;
|
||||||
|
const leftHandle = ReactTestUtils.scryRenderedDOMComponentsWithClass(slider, 'rc-slider-handle')[0];
|
||||||
|
slider.onMouseDown({
|
||||||
|
type: 'mousedown',
|
||||||
|
target: leftHandle,
|
||||||
|
pageX: 5, button: 0,
|
||||||
|
stopPropagation() {},
|
||||||
|
preventDefault() {},
|
||||||
|
});
|
||||||
|
expect(slider.dragOffset).to.be(5);
|
||||||
|
slider.onMouseMove({
|
||||||
|
type: 'mousemove',
|
||||||
|
target: leftHandle,
|
||||||
|
pageX: 14, button: 0,
|
||||||
|
stopPropagation() {},
|
||||||
|
preventDefault() {},
|
||||||
|
});
|
||||||
|
expect(slider.getValue()).to.be(9);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set `dragOffset` to 0 when the MouseEvent target isn\'t a handle', () => {
|
||||||
|
const slider = ReactDOM.render(<Slider />, div);
|
||||||
|
const sliderTrack = ReactTestUtils.scryRenderedDOMComponentsWithClass(slider, 'rc-slider-track')[0];
|
||||||
|
slider.onMouseDown({
|
||||||
|
type: 'mousedown',
|
||||||
|
target: sliderTrack,
|
||||||
|
pageX: 5, button: 0,
|
||||||
|
stopPropagation() {},
|
||||||
|
preventDefault() {},
|
||||||
|
});
|
||||||
|
expect(slider.dragOffset).to.be(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set `dragOffset` to correct value when the left handle is touched off-center', () => {
|
||||||
|
const slider = ReactDOM.render(<Slider />, div);
|
||||||
|
const leftHandle = ReactTestUtils.scryRenderedDOMComponentsWithClass(slider, 'rc-slider-handle')[0];
|
||||||
|
slider.onTouchStart({
|
||||||
|
type: 'touchstart',
|
||||||
|
target: leftHandle,
|
||||||
|
touches: [{ pageX: 5 }],
|
||||||
|
stopPropagation() {},
|
||||||
|
preventDefault() {},
|
||||||
|
});
|
||||||
|
expect(slider.dragOffset).to.be(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should respect `dragOffset` while dragging the handle via TouchEvents', () => {
|
||||||
|
const SliderWrapper = createSliderWrapperComponent();
|
||||||
|
const slider = ReactDOM.render(<SliderWrapper/>, div).refs.slider;
|
||||||
|
const leftHandle = ReactTestUtils.scryRenderedDOMComponentsWithClass(slider, 'rc-slider-handle')[0];
|
||||||
|
slider.onTouchStart({
|
||||||
|
type: 'touchstart',
|
||||||
|
target: leftHandle,
|
||||||
|
touches: [{ pageX: 5 }],
|
||||||
|
stopPropagation() {},
|
||||||
|
preventDefault() {},
|
||||||
|
});
|
||||||
|
expect(slider.dragOffset).to.be(5);
|
||||||
|
slider.onTouchMove({
|
||||||
|
type: 'touchmove',
|
||||||
|
target: leftHandle,
|
||||||
|
touches: [{ pageX: 14 }],
|
||||||
|
stopPropagation() {},
|
||||||
|
preventDefault() {},
|
||||||
|
});
|
||||||
|
expect(slider.getValue()).to.be(9);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set `dragOffset` to 0 when the TouchEvent target isn\'t a handle', () => {
|
||||||
|
const slider = ReactDOM.render(<Slider />, div);
|
||||||
|
const sliderTrack = ReactTestUtils.scryRenderedDOMComponentsWithClass(slider, 'rc-slider-track')[0];
|
||||||
|
slider.onTouchStart({
|
||||||
|
type: 'touchstart',
|
||||||
|
target: sliderTrack,
|
||||||
|
touches: [{ pageX: 5 }],
|
||||||
|
stopPropagation() {},
|
||||||
|
preventDefault() {},
|
||||||
|
});
|
||||||
|
expect(slider.dragOffset).to.be(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user