Skip to content

Commit

Permalink
feat: add new events on text input
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Cesarato committed Aug 6, 2020
1 parent 8441af7 commit 34264cb
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class InputSpinner extends Component {
max: this.parseNum(this.props.max),
value: this.parseNum(this.props.value),
step: spinnerStep,
focused: false,
buttonPress: null,
};
}
Expand Down Expand Up @@ -239,6 +240,40 @@ class InputSpinner extends Component {
}
}

/**
* On Focus
* @returns {*}
* @param e
*/
onFocus(e){
if (this.props.onFocus) {
this.props.onFocus(e);
}
this.setState({focused: true});
}

/**
* On Blur
* @returns {*}
* @param e
*/
onBlur(e){
if (this.props.onBlur) {
this.props.onBlur(e);
}
this.setState({focused: false});
}

/**
* On Key Press
* @returns {*}
* @param e
*/
onKeyPress(e){
if (this.props.onKeyPress) {
this.props.onKeyPress(e);
}
}

/**
* Max is reached
Expand All @@ -264,6 +299,27 @@ class InputSpinner extends Component {
return num <= this.state.min;
}

/**
* Blur
*/
blur() {
this.textInput.blur();
}

/**
* Focus
*/
focus() {
this.textInput.focus();
}

/**
* Clear
*/
clear() {
this.textInput.clear();
}

/**
* Is object empty
* @param obj
Expand All @@ -290,6 +346,14 @@ class InputSpinner extends Component {
return !this.props.disabled && this.props.editable;
}

/**
* Is text input focused
* @returns {boolean|Boolean}
*/
isFocused() {
return this.state.focus;
}

/**
* Is left button disabled
* @returns {Boolean}
Expand Down Expand Up @@ -672,9 +736,15 @@ class InputSpinner extends Component {
{this.props.prepend}

<TextInput
ref={input => this.textInput = input}
style={this._getInputTextStyle()}
value={this.getValue()}
autofocus={this.props.autofocus}
editable={this.isEditable()}
maxLength={this.props.maxLength}
onKeyPress={this.onKeyPress.bind(this)}
onFocus={this.onFocus.bind(this)}
onBlur={this.onBlur.bind(this)}
keyboardType={this._getKeyboardType()}
onChangeText={this.onChange.bind(this)}
onSubmitEditing={this.onSubmit.bind(this)}
Expand Down Expand Up @@ -713,11 +783,16 @@ InputSpinner.propTypes = {
buttonFontSize: PropTypes.number,
buttonFontFamily: PropTypes.string,
buttonTextColor: PropTypes.string,
maxLength: PropTypes.number,
disabled: PropTypes.bool,
editable: PropTypes.bool,
autofocus: PropTypes.bool,
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
onChange: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
onKeyPress: PropTypes.func,
onMin: PropTypes.func,
onMax: PropTypes.func,
onIncrease: PropTypes.func,
Expand Down Expand Up @@ -763,8 +838,10 @@ InputSpinner.defaultProps = {
buttonFontFamily: null,
buttonTextColor: "#FFFFFF",
buttonPressTextColor: "#FFFFFF",
maxLength: null,
disabled: false,
editable: true,
autofocus: false,
width: 150,
height: 50,
buttonLeftDisabled: false,
Expand Down

0 comments on commit 34264cb

Please sign in to comment.