Skip to content

Commit

Permalink
Add flag update when phones changes through props
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Anstey committed Feb 4, 2018
1 parent ad57239 commit 9d58356
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions __tests__/TelInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,19 @@ describe('TelInput', function () { // eslint-disable-line func-names
});

it('should change input value on value prop change', () => {
const subject = this.makeSubject();
const flagComponent = subject.find(FlagDropDown);

subject.setProps({ value: '+447598455159' });

expect(flagComponent.props().highlightedCountry).toBe(1);

subject.setProps({ value: '+1(201) 555-0129' });

expect(flagComponent.props().highlightedCountry).toBe(0);
});

it('should update country flag when value updates', () => {
const subject = this.makeSubject();
const inputComponent = subject.find(TelInput);

Expand Down
6 changes: 6 additions & 0 deletions src/components/IntlTelInputApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ class IntlTelInputApp extends Component {
}
}

componentDidUpdate(prevProps) {
if (this.props.value !== prevProps.value) {
this.updateFlagFromNumber(this.props.value);
}
}

componentWillUnmount() {
document.removeEventListener('keydown', this.handleDocumentKeyDown);
window.removeEventListener('scroll', this.handleWindowScroll);
Expand Down

0 comments on commit 9d58356

Please sign in to comment.