radon-select
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -9,3 +9,3 @@ var React = require('react'); | ||
return { | ||
carValue: "audi" | ||
carValue: "bmw" | ||
}; | ||
@@ -58,3 +58,3 @@ }, | ||
<h3>Get and set values</h3> | ||
<RadonSelect ref="car" selectName="car" onChange={this.onCarChange}> | ||
<RadonSelect ref="car" selectName="car" defaultValue={this.state.carValue} onChange={this.onCarChange}> | ||
<RadonSelect.Option value="audi">audi</RadonSelect.Option> | ||
@@ -61,0 +61,0 @@ <RadonSelect.Option value="bmw">bmw</RadonSelect.Option> |
@@ -41,3 +41,2 @@ 'use strict'; | ||
selectName: React.PropTypes.string.isRequired, | ||
// TODO | ||
defaultValue: React.PropTypes.string, | ||
@@ -76,5 +75,9 @@ placeholderText: React.PropTypes.string, | ||
getInitialState: function getInitialState() { | ||
var initialIndex = this.props.defaultValue !== undefined ? this.getValueIndex(this.props.defaultValue) : -1; | ||
var defaultValue = initialIndex === -1 ? this.props.children[0].props.value : this.props.defaultValue; | ||
return { | ||
selectedOptionIndex: false, | ||
selectedOptionVal: this.props.children[0].props.value, | ||
selectedOptionIndex: initialIndex === -1 ? false : initialIndex, | ||
selectedOptionVal: defaultValue, | ||
open: false, | ||
@@ -84,2 +87,10 @@ focus: false | ||
}, | ||
getValueIndex: function getValueIndex(val) { | ||
for (var i = 0; i < this.props.children.length; ++i) { | ||
if (this.props.children[i].props.value === val) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
}, | ||
getValue: function getValue() { | ||
@@ -89,15 +100,13 @@ return this.state.selectedOptionVal; | ||
setValue: function setValue(val, silent) { | ||
for (var i = 0; i < this.props.children.length; i++) { | ||
if (this.props.children[i].props.value === val) { | ||
this.setState({ | ||
selectedOptionIndex: i, | ||
selectedOptionVal: val | ||
}, function () { | ||
if (!silent) { | ||
this.props.onChange(this.state.selectedOptionVal); | ||
} | ||
}); | ||
var index = this.getValueIndex(val); | ||
break; | ||
} | ||
if (index !== -1) { | ||
this.setState({ | ||
selectedOptionIndex: index, | ||
selectedOptionVal: val | ||
}, function () { | ||
if (!silent) { | ||
this.props.onChange(this.state.selectedOptionVal); | ||
} | ||
}); | ||
} | ||
@@ -104,0 +113,0 @@ }, |
{ | ||
"name": "radon-select", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "React select box replacement component", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -41,3 +41,2 @@ 'use strict'; | ||
selectName: React.PropTypes.string.isRequired, | ||
// TODO | ||
defaultValue: React.PropTypes.string, | ||
@@ -76,5 +75,13 @@ placeholderText: React.PropTypes.string, | ||
getInitialState () { | ||
var initialIndex = this.props.defaultValue !== undefined | ||
? this.getValueIndex(this.props.defaultValue) | ||
: -1; | ||
var defaultValue = initialIndex === -1 | ||
? this.props.children[0].props.value | ||
: this.props.defaultValue; | ||
return { | ||
selectedOptionIndex: false, | ||
selectedOptionVal: this.props.children[0].props.value, | ||
selectedOptionIndex: initialIndex === -1 ? false : initialIndex, | ||
selectedOptionVal: defaultValue, | ||
open: false, | ||
@@ -84,2 +91,10 @@ focus: false | ||
}, | ||
getValueIndex (val) { | ||
for (var i = 0; i < this.props.children.length; ++i) { | ||
if (this.props.children[i].props.value === val) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
}, | ||
getValue () { | ||
@@ -89,15 +104,13 @@ return this.state.selectedOptionVal; | ||
setValue (val, silent) { | ||
for (var i = 0; i < this.props.children.length; i++) { | ||
if (this.props.children[i].props.value === val) { | ||
this.setState({ | ||
selectedOptionIndex: i, | ||
selectedOptionVal: val | ||
}, function () { | ||
if (!silent) { | ||
this.props.onChange(this.state.selectedOptionVal); | ||
} | ||
}); | ||
var index = this.getValueIndex(val); | ||
break; | ||
} | ||
if (index !== -1) { | ||
this.setState({ | ||
selectedOptionIndex: index, | ||
selectedOptionVal: val | ||
}, function () { | ||
if (!silent) { | ||
this.props.onChange(this.state.selectedOptionVal); | ||
} | ||
}); | ||
} | ||
@@ -104,0 +117,0 @@ }, |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
73078
25
1124
1