Skip to content

Commit 6ebd217

Browse files
authored
Execute onChange for empty value (close #272)
1 parent 5483d27 commit 6ebd217

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ class PhoneInput extends React.Component {
492492

493493
handleInput = (e) => {
494494
const { value } = e.target;
495-
const { prefix } = this.props;
495+
const { prefix, onChange } = this.props;
496496

497497
let formattedNumber = this.props.disableCountryCode ? '' : prefix;
498498
let newSelectedCountry = this.state.selectedCountry;
@@ -507,7 +507,11 @@ class PhoneInput extends React.Component {
507507
if (value.slice(0, updatedInput.length) !== updatedInput) return;
508508
}
509509

510-
if (value === prefix) return this.setState({ formattedNumber: '' });
510+
if (value === prefix) {
511+
// we should handle change when we delete the last digit
512+
if (onChange) onChange('', this.getCountryData(), e, '');
513+
return this.setState({ formattedNumber: '' });
514+
}
511515

512516
// Does not exceed 15 digit phone number limit
513517
if (value.replace(/\D/g, '').length > 15 && !this.state.enableLongNumbers) return;
@@ -522,7 +526,7 @@ class PhoneInput extends React.Component {
522526
e.returnValue = false;
523527
}
524528

525-
const { country, onChange } = this.props
529+
const { country } = this.props
526530
const { onlyCountries, selectedCountry, hiddenAreaCodes } = this.state
527531

528532
if (onChange) e.persist();

0 commit comments

Comments
 (0)