Skip to content

Commit

Permalink
[Slider] Return 'defaultValue' back
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI committed Oct 30, 2015
1 parent 28a0477 commit a3e9cad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions docs/src/app/components/pages/components/sliders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -125,8 +131,8 @@ class SlidersPage extends React.Component {
componentInfo={componentInfo}>
<CodeExample code={Code}>
<Slider name="slider1" />
<Slider name="slider2" value={0.5} step={0.10} />
<Slider name="slider3" value={1}/>
<Slider name="slider2" defaultValue={0.5} step={0.10} />
<Slider name="slider3" defaultValue={1}/>
<Slider name="slider1" disabled={true} />
<Slider name="slider2" disabled={true} value={0.5} />
<Slider name="slider3" disabled={true} value={1} />
Expand Down
4 changes: 2 additions & 2 deletions docs/src/app/components/raw-code/sliders-code.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//Default
<Slider name="slider1" />
// With starting value
<Slider name="slider2" value={0.5} step={0.10} />
<Slider name="slider3" value={1} />
<Slider name="slider2" defaultValue={0.5} step={0.10} />
<Slider name="slider3" defaultValue={1} />
// Disabled with fixed value
<Slider name="slider1" disabled={true} />
<Slider name="slider2" disabled={true} value={0.5} />
Expand Down
3 changes: 2 additions & 1 deletion src/slider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a3e9cad

Please sign in to comment.