Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update flag when defaultCountry value is changed #285

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
*This project is an instance of original project made by [Patrick Wang](https://github.com/patw0929).
Because of the lack of activity on original repo, I have added some functionalities and published it on npmjs for my own personal use.
Copyright (c) 2015-2019 [Patrick Wang](https://github.com/patw0929).*

# React-Intl-Tel-Input

[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
Expand Down Expand Up @@ -119,4 +123,3 @@ yarn run lint
MIT

Copyright (c) 2015-2019 patw.

11 changes: 10 additions & 1 deletion src/components/IntlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ class IntlTelInput extends Component {
if (this.props.allowDropdown !== prevProps.allowDropdown) {
this.allowDropdown = this.props.allowDropdown;
}

if (this.props.defaultCountry !== prevProps.defaultCountry) {
this.updateFlagOnDefaultCountryChange(this.props.defaultCountry)
}
}

componentWillUnmount() {
Expand All @@ -171,6 +175,11 @@ class IntlTelInput extends Component {
this.unbindDocumentClick();
}

// Updates flag when value of defaultCountry props change
updateFlagOnDefaultCountryChange = (countryCode) => {
this.setFlag(countryCode, false)
};

getTempCountry = countryCode => {
if (countryCode === 'auto') {
return 'auto';
Expand Down Expand Up @@ -211,7 +220,7 @@ class IntlTelInput extends Component {
};

// select the given flag, update the placeholder and the active list item
// Note: called from setInitialState, updateFlagFromNumber, selectListItem, setCountry
// Note: called from setInitialState, updateFlagFromNumber, selectListItem, setCountry, updateFlagOnDefaultCountryChange
setFlag = (countryCode, isInit) => {
const prevCountry =
this.selectedCountryData && this.selectedCountryData.iso2
Expand Down