Update PowerSelector to support powerLevelKey prop
As a key to send as second argument to onChange. This is useful when passing the same callback to multiple PowerSelectors.
This commit is contained in:
@@ -42,6 +42,9 @@ module.exports = React.createClass({
|
|||||||
// should the user be able to change the value? false by default.
|
// should the user be able to change the value? false by default.
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
|
|
||||||
|
// Optional key to pass as the second argument to `onChange`
|
||||||
|
powerLevelKey: PropTypes.string,
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
@@ -84,17 +87,17 @@ module.exports = React.createClass({
|
|||||||
onSelectChange: function(event) {
|
onSelectChange: function(event) {
|
||||||
this.setState({ custom: event.target.value === "SELECT_VALUE_CUSTOM" });
|
this.setState({ custom: event.target.value === "SELECT_VALUE_CUSTOM" });
|
||||||
if (event.target.value !== "SELECT_VALUE_CUSTOM") {
|
if (event.target.value !== "SELECT_VALUE_CUSTOM") {
|
||||||
this.props.onChange(event.target.value);
|
this.props.onChange(event.target.value, this.props.powerLevelKey);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onCustomBlur: function(event) {
|
onCustomBlur: function(event) {
|
||||||
this.props.onChange(parseInt(this.refs.custom.value));
|
this.props.onChange(parseInt(this.refs.custom.value), this.props.powerLevelKey);
|
||||||
},
|
},
|
||||||
|
|
||||||
onCustomKeyDown: function(event) {
|
onCustomKeyDown: function(event) {
|
||||||
if (event.key == "Enter") {
|
if (event.key == "Enter") {
|
||||||
this.props.onChange(parseInt(this.refs.custom.value));
|
this.props.onChange(parseInt(this.refs.custom.value), this.props.powerLevelKey);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user