From 29964f5f8f8e32630ac626345e6fa88bacd8522f Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Fri, 4 Sep 2015 00:39:48 +0300 Subject: [PATCH 1/3] Remove redundant 'defaultValue'. Fix bug when 'min' greater than zero. --- docs/src/app/components/pages/components/sliders.jsx | 10 ++-------- docs/src/app/components/raw-code/sliders-code.txt | 4 ++-- src/slider.jsx | 4 +--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/docs/src/app/components/pages/components/sliders.jsx b/docs/src/app/components/pages/components/sliders.jsx index 77c8903770b84d..64cd719806ae13 100644 --- a/docs/src/app/components/pages/components/sliders.jsx +++ b/docs/src/app/components/pages/components/sliders.jsx @@ -23,12 +23,6 @@ class SlidersPage extends React.Component { header: 'required', desc: 'The name of the slider. Behaves like the name attribute of an input element.' }, - { - name: 'defaultValue', - type: 'number', - header: 'default: 0', - desc: 'The default value of the slider.' - }, { name: 'description', type: 'string', @@ -131,8 +125,8 @@ class SlidersPage extends React.Component { componentInfo={componentInfo}> - - + + diff --git a/docs/src/app/components/raw-code/sliders-code.txt b/docs/src/app/components/raw-code/sliders-code.txt index 47cb3c6e6c4f34..2dcb8ea847b2b1 100644 --- a/docs/src/app/components/raw-code/sliders-code.txt +++ b/docs/src/app/components/raw-code/sliders-code.txt @@ -1,8 +1,8 @@ //Default // With starting value - - + + // Disabled with fixed value diff --git a/src/slider.jsx b/src/slider.jsx index c0b2cfce7a1c06..c830c9953ac336 100644 --- a/src/slider.jsx +++ b/src/slider.jsx @@ -51,7 +51,6 @@ const Slider = React.createClass({ propTypes: { name: React.PropTypes.string.isRequired, - defaultValue: valueInRangePropType, description: React.PropTypes.string, disabled: React.PropTypes.bool, error: React.PropTypes.string, @@ -80,7 +79,6 @@ const Slider = React.createClass({ getDefaultProps() { return { - defaultValue: 0, disabled: false, max: 1, min: 0, @@ -92,7 +90,7 @@ const Slider = React.createClass({ getInitialState() { let value = this.props.value; if (value === undefined) { - value = this.props.defaultValue; + value = this.props.min; } let percent = (value - this.props.min) / (this.props.max - this.props.min); if (isNaN(percent)) percent = 0; From 28a0477573bbbed59bb4473902ff38106de0f6a3 Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Fri, 4 Sep 2015 18:48:19 +0300 Subject: [PATCH 2/3] Fix value update while dragging --- src/slider.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slider.jsx b/src/slider.jsx index c830c9953ac336..f71365f66dbb38 100644 --- a/src/slider.jsx +++ b/src/slider.jsx @@ -110,7 +110,7 @@ const Slider = React.createClass({ let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme; this.setState({muiTheme: newMuiTheme}); - if (nextProps.value !== undefined) { + if (nextProps.value !== undefined && !this.state.dragging) { this.setValue(nextProps.value); } }, From a3e9cad6c31703c1ed40311b0b3b98e910ee5b8f Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Fri, 30 Oct 2015 19:35:44 +0300 Subject: [PATCH 3/3] [Slider] Return 'defaultValue' back --- docs/src/app/components/pages/components/sliders.jsx | 10 ++++++++-- docs/src/app/components/raw-code/sliders-code.txt | 4 ++-- src/slider.jsx | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/src/app/components/pages/components/sliders.jsx b/docs/src/app/components/pages/components/sliders.jsx index 64cd719806ae13..77c8903770b84d 100644 --- a/docs/src/app/components/pages/components/sliders.jsx +++ b/docs/src/app/components/pages/components/sliders.jsx @@ -23,6 +23,12 @@ class SlidersPage extends React.Component { header: 'required', desc: 'The name of the slider. Behaves like the name attribute of an input element.' }, + { + name: 'defaultValue', + type: 'number', + header: 'default: 0', + desc: 'The default value of the slider.' + }, { name: 'description', type: 'string', @@ -125,8 +131,8 @@ class SlidersPage extends React.Component { componentInfo={componentInfo}> - - + + diff --git a/docs/src/app/components/raw-code/sliders-code.txt b/docs/src/app/components/raw-code/sliders-code.txt index 2dcb8ea847b2b1..47cb3c6e6c4f34 100644 --- a/docs/src/app/components/raw-code/sliders-code.txt +++ b/docs/src/app/components/raw-code/sliders-code.txt @@ -1,8 +1,8 @@ //Default // With starting value - - + + // Disabled with fixed value diff --git a/src/slider.jsx b/src/slider.jsx index f71365f66dbb38..dd804ed938bc72 100644 --- a/src/slider.jsx +++ b/src/slider.jsx @@ -51,6 +51,7 @@ const Slider = React.createClass({ propTypes: { name: React.PropTypes.string.isRequired, + defaultValue: valueInRangePropType, description: React.PropTypes.string, disabled: React.PropTypes.bool, error: React.PropTypes.string, @@ -90,7 +91,7 @@ const Slider = React.createClass({ getInitialState() { let value = this.props.value; if (value === undefined) { - value = this.props.min; + value = this.props.defaultValue !== undefined ? this.props.defaultValue : this.props.min; } let percent = (value - this.props.min) / (this.props.max - this.props.min); if (isNaN(percent)) percent = 0;