mirror of
https://github.com/wassname/slider.git
synced 2026-09-10 12:38:09 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a6fb5a570 | ||
|
|
53aa61faf2 | ||
|
|
9655483bf5 | ||
|
|
faa4f384a3 | ||
|
|
18ddbb796c | ||
|
|
051fef6603 | ||
|
|
b325daef48 | ||
|
|
db47c3d27d | ||
|
|
f20014a9d4 | ||
|
|
6074d5fc43 | ||
|
|
34754440ed |
@@ -1,6 +1,11 @@
|
||||
# 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
|
||||
|
||||
[#133](https://github.com/react-component/slider/pull/133) support multi-range ([@sosz](https://github.com/sosz))
|
||||
|
||||
+20
-7
@@ -23,13 +23,19 @@
|
||||
|
||||
.@{prefixClass} {
|
||||
position: relative;
|
||||
height: 4px;
|
||||
height: 14px;
|
||||
padding: 5px 0;
|
||||
width: 100%;
|
||||
border-radius: @border-radius-base;
|
||||
background-color: #e9e9e9;
|
||||
|
||||
.borderBox();
|
||||
|
||||
&-rail {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
background-color: #e9e9e9;
|
||||
height: 4px;
|
||||
}
|
||||
|
||||
&-track {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
@@ -62,7 +68,7 @@
|
||||
|
||||
&-mark {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
top: 18px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
font-size: 12px;
|
||||
@@ -130,23 +136,30 @@
|
||||
}
|
||||
|
||||
.@{prefixClass}-vertical {
|
||||
width: 4px;
|
||||
width: 14px;
|
||||
height: 100%;
|
||||
padding: 0 5px;
|
||||
|
||||
.@{prefixClass} {
|
||||
&-rail {
|
||||
height: 100%;
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&-track {
|
||||
left: 5px;
|
||||
bottom: 0;
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&-handle {
|
||||
position: absolute;
|
||||
margin-left: -5px;
|
||||
margin-bottom: -7px;
|
||||
}
|
||||
|
||||
&-mark {
|
||||
top: 0;
|
||||
left: 10px;
|
||||
left: 18px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rc-slider",
|
||||
"version": "5.1.1",
|
||||
"version": "5.3.3",
|
||||
"description": "slider ui component for react",
|
||||
"keywords": [
|
||||
"react",
|
||||
@@ -19,10 +19,14 @@
|
||||
},
|
||||
"files": [
|
||||
"assets/*.css",
|
||||
"lib"
|
||||
"lib",
|
||||
"dist"
|
||||
],
|
||||
"licenses": "MIT",
|
||||
"main": "./lib/index.js",
|
||||
"entry": {
|
||||
"rc-slider": ["./assets/index.less", "./src/index.js"]
|
||||
},
|
||||
"style": "./assets/index.css",
|
||||
"config": {
|
||||
"port": 8005
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ const Marks = ({ className, vertical, marks, included, upperBound, lowerBound, m
|
||||
|
||||
const bottomStyle = {
|
||||
// height: markWidth + '%',
|
||||
marginBottom: '-200%',
|
||||
marginBottom: '-50%',
|
||||
bottom: `${(point - min) / range * 100}%`,
|
||||
};
|
||||
|
||||
|
||||
+37
-5
@@ -1,3 +1,4 @@
|
||||
import { findDOMNode } from 'react-dom';
|
||||
import React, { cloneElement } from 'react';
|
||||
import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
||||
import classNames from 'classnames';
|
||||
@@ -22,6 +23,13 @@ function getMousePosition(vertical, e) {
|
||||
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) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
@@ -93,7 +101,7 @@ class Slider extends React.Component {
|
||||
const isNotControlled = !('value' in props);
|
||||
if (isNotControlled) {
|
||||
this.setState(state);
|
||||
} else if (state.handle) {
|
||||
} else if (state.handle !== undefined) {
|
||||
this.setState({ handle: state.handle });
|
||||
}
|
||||
|
||||
@@ -104,7 +112,7 @@ class Slider extends React.Component {
|
||||
|
||||
onMouseMove(e) {
|
||||
const position = getMousePosition(this.props.vertical, e);
|
||||
this.onMove(e, position);
|
||||
this.onMove(e, position - this.dragOffset);
|
||||
}
|
||||
|
||||
onTouchMove(e) {
|
||||
@@ -114,7 +122,7 @@ class Slider extends React.Component {
|
||||
}
|
||||
|
||||
const position = getTouchPosition(this.props.vertical, e);
|
||||
this.onMove(e, position);
|
||||
this.onMove(e, position - this.dragOffset);
|
||||
}
|
||||
|
||||
onMove(e, position) {
|
||||
@@ -149,7 +157,14 @@ class Slider extends React.Component {
|
||||
onTouchStart(e) {
|
||||
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.addDocumentEvents('touch');
|
||||
pauseEvent(e);
|
||||
@@ -157,7 +172,15 @@ class Slider extends React.Component {
|
||||
|
||||
onMouseDown(e) {
|
||||
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.addDocumentEvents('mouse');
|
||||
pauseEvent(e);
|
||||
@@ -259,6 +282,13 @@ class Slider extends React.Component {
|
||||
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) {
|
||||
return value < props.min || value > props.max;
|
||||
}
|
||||
@@ -457,6 +487,7 @@ class Slider extends React.Component {
|
||||
offset: offsets[i],
|
||||
dragging: handle === i,
|
||||
key: i,
|
||||
ref: `handle-${i}`,
|
||||
}));
|
||||
if (!range) { handles.shift(); }
|
||||
|
||||
@@ -487,6 +518,7 @@ class Slider extends React.Component {
|
||||
onTouchStart={disabled ? noop : this.onTouchStart.bind(this)}
|
||||
onMouseDown={disabled ? noop : this.onMouseDown.bind(this)}
|
||||
>
|
||||
<div className={`${prefixCls}-rail`} />
|
||||
{tracks}
|
||||
<Steps prefixCls={prefixCls} vertical = {vertical} marks={marks} dots={dots} step={step}
|
||||
included={isIncluded} lowerBound={bounds[0]}
|
||||
|
||||
+108
@@ -5,6 +5,18 @@ const ReactDOM = require('react-dom');
|
||||
const ReactTestUtils = require('react-addons-test-utils');
|
||||
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');
|
||||
|
||||
describe('rc-slider', function test() {
|
||||
@@ -232,4 +244,100 @@ describe('rc-slider', function test() {
|
||||
|
||||
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