Skip to content

Commit

Permalink
fix: #226
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoidjk committed Jul 3, 2017
1 parent 89353ad commit 6235e1f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
25 changes: 25 additions & 0 deletions examples/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ class ControlledRange extends React.Component {
}
}

// https://github.com/react-component/slider/issues/226
class PureRenderRange extends React.Component {
constructor(props) {
super(props);
this.state = {
foo: false,
};
}
handleChange = (value) => {
console.log(value);
this.setState({
foo: !this.state.foo,
});
}
render() {
return (
<Range defaultValue={[20, 40, 60, 80]} onChange={this.handleChange} allowCross={false} />
);
}
}

ReactDOM.render(
<div>
<div style={style}>
Expand Down Expand Up @@ -153,5 +174,9 @@ ReactDOM.render(
<p>Range with dynamic `max` `min`</p>
<DynamicBounds />
</div>
<div style={style}>
<p>Range as child component</p>
<PureRenderRange />
</div>
</div>
, document.getElementById('__react-content'));
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-slider",
"version": "8.1.3",
"version": "8.1.4",
"description": "Slider UI component for React",
"keywords": [
"react",
Expand Down Expand Up @@ -74,6 +74,7 @@
"prop-types": "^15.5.4",
"rc-tooltip": "^3.4.2",
"rc-util": "^4.0.4",
"shallowequal": "^1.0.1",
"warning": "^3.0.0"
}
}
6 changes: 6 additions & 0 deletions src/Range.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import shallowEqual from 'shallowequal';
import Track from './common/Track';
import createSlider from './common/createSlider';
import * as utils from './utils';
Expand Down Expand Up @@ -48,6 +49,11 @@ class Range extends React.Component {

componentWillReceiveProps(nextProps) {
if (!('value' in nextProps || 'min' in nextProps || 'max' in nextProps)) return;
if (this.props.min === nextProps.min &&
this.props.max === nextProps.max &&
shallowEqual(this.props.value, nextProps.value)) {
return;
}
const { bounds } = this.state;
const value = nextProps.value || bounds;
const nextBounds = value.map(v => this.trimAlignValue(v, nextProps));
Expand Down

0 comments on commit 6235e1f

Please sign in to comment.