diff --git a/lib/index.js b/lib/index.js index 9ce4bd6c..c741a78e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -51,13 +51,15 @@ export default class PhoneInput extends Component { this.setState({ value }); this.updateFlagAndFormatNumber(value); } + + nextProps.focus && this.focus(); } onChangePhoneNumber(number) { const actionAfterSetState = this.props.onChangePhoneNumber ? () => { - this.props.onChangePhoneNumber(number); - } + this.props.onChangePhoneNumber(number); + } : null; this.updateFlagAndFormatNumber(number, actionAfterSetState); } @@ -154,6 +156,7 @@ export default class PhoneInput extends Component { ? phoneNumber : this.possiblyEliminateZeroAfterCountryCode(phoneNumber); iso2 = PhoneNumber.getCountryCodeOfNumber(phoneNumber); + } this.setState({ iso2, formattedNumber: this.format(phoneNumber) }, actionAfterSetState); } @@ -169,12 +172,9 @@ export default class PhoneInput extends Component { this.inputPhone.focus(); } - blur() { - this.inputPhone.blur(); - } - render() { const { iso2, formattedNumber, disabled } = this.state; + const { focus, returnKey } = this.props; const TextComponent = this.props.textComponent || TextInput; return ( @@ -199,6 +199,8 @@ export default class PhoneInput extends Component { onChangeText={text => { this.onChangePhoneNumber(text); }} + autoFocus={focus} + returnKeyType={returnKey ? 'done' : null} keyboardType="phone-pad" underlineColorAndroid="rgba(0,0,0,0)" value={formattedNumber}