From c731a6b913b5d8852d886c4b0e35ae7cbc7c37b7 Mon Sep 17 00:00:00 2001 From: Matthew Anstey Date: Sat, 24 Feb 2018 23:41:09 +0000 Subject: [PATCH] Allow country code to be deleted --- __tests__/TelInput.test.js | 10 ++++++++++ src/components/IntlTelInputApp.js | 3 --- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/__tests__/TelInput.test.js b/__tests__/TelInput.test.js index 2ddbac789..90db68f86 100644 --- a/__tests__/TelInput.test.js +++ b/__tests__/TelInput.test.js @@ -446,6 +446,16 @@ describe('TelInput', function () { // eslint-disable-line func-names subject.setProps({ value: 'foo bar' }); expect(inputComponent.props().value).toBe('foo bar'); }); + + it('should be able to delete country code after input field has been populated with number', () => { + const subject = this.makeSubject(); + + subject.setProps({ value: '+447598455159' }); + + subject.setProps({ value: '+' }); + + expect(subject.state().value).toBe('+'); + }); }); describe('uncontrolled', () => { diff --git a/src/components/IntlTelInputApp.js b/src/components/IntlTelInputApp.js index 9338c3ae3..c39a4f0ca 100644 --- a/src/components/IntlTelInputApp.js +++ b/src/components/IntlTelInputApp.js @@ -726,9 +726,6 @@ class IntlTelInputApp extends Component { // Note: use getNumeric here because the number has not been // formatted yet, so could contain bad chars countryCode = null; - } else if (!number || number === '+') { - // empty, or just a plus, so default - countryCode = this.defaultCountry; } if (countryCode !== null) {