mirror of
https://github.com/wassname/slider.git
synced 2026-09-11 12:42:49 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b8e27e613 | ||
|
|
e438757a64 | ||
|
|
aad5fef20c | ||
|
|
1568019a59 | ||
|
|
abdb297c16 | ||
|
|
67b76953c6 | ||
|
|
b6d8f389ef |
+3
-3
@@ -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=
|
||||||
@@ -39,4 +39,4 @@ env:
|
|||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- env: "TEST_TYPE=saucelabs"
|
- env: "TEST_TYPE=saucelabs"
|
||||||
|
|||||||
+1
-1
@@ -228,7 +228,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.rc-tooltip {
|
.@{prefixClass}-tooltip {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: -9999px;
|
left: -9999px;
|
||||||
top: -9999px;
|
top: -9999px;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rc-slider",
|
"name": "rc-slider",
|
||||||
"version": "4.0.1",
|
"version": "5.1.0",
|
||||||
"description": "slider ui component for react",
|
"description": "slider ui component for react",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"react",
|
"react",
|
||||||
|
|||||||
+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,
|
||||||
|
|||||||
+15
-2
@@ -5,6 +5,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() {
|
||||||
}
|
}
|
||||||
@@ -30,7 +31,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 +45,15 @@ class Slider extends React.Component {
|
|||||||
recent = bounds.length - 1;
|
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 = {
|
this.state = {
|
||||||
handle: null,
|
handle: null,
|
||||||
recent,
|
recent,
|
||||||
@@ -115,7 +125,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];
|
||||||
@@ -400,6 +410,7 @@ class Slider extends React.Component {
|
|||||||
const {
|
const {
|
||||||
className,
|
className,
|
||||||
prefixCls,
|
prefixCls,
|
||||||
|
tooltipPrefixCls,
|
||||||
disabled,
|
disabled,
|
||||||
vertical,
|
vertical,
|
||||||
dots,
|
dots,
|
||||||
@@ -430,6 +441,7 @@ class Slider extends React.Component {
|
|||||||
|
|
||||||
const commonHandleProps = {
|
const commonHandleProps = {
|
||||||
prefixCls,
|
prefixCls,
|
||||||
|
tooltipPrefixCls,
|
||||||
noTip: isNoTip,
|
noTip: isNoTip,
|
||||||
tipTransitionName,
|
tipTransitionName,
|
||||||
tipFormatter,
|
tipFormatter,
|
||||||
@@ -505,6 +517,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,
|
||||||
|
|||||||
@@ -207,4 +207,29 @@ 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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user