Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/components/IntlTelInputApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class IntlTelInputApp extends Component {
this.autoCountryLoaded = this.autoCountryLoaded.bind(this);
this.getDialCode = this.getDialCode.bind(this);
this.handleOnBlur = this.handleOnBlur.bind(this);
this.handleOnFocus = this.handleOnFocus.bind(this);
this.handleSelectedFlagKeydown = this.handleSelectedFlagKeydown.bind(this);
this.setInitialState = this.setInitialState.bind(this);
this.setNumber = this.setNumber.bind(this);
Expand Down Expand Up @@ -784,6 +785,18 @@ class IntlTelInputApp extends Component {
}
}

handleOnFocus() {
if (typeof this.props.onPhoneNumberFocus === 'function') {
const value = this.state.value;
const fullNumber = this.formatFullNumber(value);
const isValid = this.isValidNumber(fullNumber);

this.props.onPhoneNumberFocus(
isValid, value, this.selectedCountryData,
fullNumber, this.getExtension(value));
}
}

bindDocumentClick() {
this.isOpening = true;
document.querySelector('html').addEventListener('click', this.handleDocumentClick);
Expand Down Expand Up @@ -1185,6 +1198,7 @@ class IntlTelInputApp extends Component {
refCallback={ this.setTelRef }
handleInputChange={ this.handleInputChange }
handleOnBlur={ this.handleOnBlur }
handleOnFocus={ this.handleOnFocus }
className={ inputClass }
disabled={ this.state.disabled }
readonly={ this.state.readonly }
Expand Down Expand Up @@ -1232,6 +1246,7 @@ IntlTelInputApp.propTypes = {
utilsScript: PropTypes.string,
onPhoneNumberChange: PropTypes.func,
onPhoneNumberBlur: PropTypes.func,
onPhoneNumberFocus: PropTypes.func,
onSelectFlag: PropTypes.func,
disabled: PropTypes.bool,
placeholder: PropTypes.string,
Expand Down Expand Up @@ -1283,6 +1298,7 @@ IntlTelInputApp.defaultProps = {
utilsScript: '',
onPhoneNumberChange: null,
onPhoneNumberBlur: null,
onPhoneNumberFocus: null,
onSelectFlag: null,
disabled: false,
autoFocus: false,
Expand Down
2 changes: 2 additions & 0 deletions src/components/TelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TelInput extends Component {
placeholder={ this.props.placeholder }
onChange={ this.props.handleInputChange }
onBlur={ this.props.handleOnBlur }
onFocus={ this.props.handleOnFocus }
autoFocus={ this.props.autoFocus }
/>
);
Expand All @@ -49,6 +50,7 @@ TelInput.propTypes = {
placeholder: PropTypes.string,
handleInputChange: PropTypes.func,
handleOnBlur: PropTypes.func,
handleOnFocus: PropTypes.func,
autoFocus: PropTypes.bool,
autoComplete: PropTypes.string,
inputProps: PropTypes.object, // eslint-disable-line react/forbid-prop-types
Expand Down