From c44d7b6c44bdb2e0a4e0243e0ca5ae307f14dc48 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 17 May 2017 13:04:06 +0100 Subject: [PATCH] Improve phone number country dropdown for registration and login This implements https://github.com/vector-im/riot-web/issues/3895 --- src/components/views/login/CountryDropdown.js | 21 +++++++++++-- src/components/views/login/PasswordLogin.js | 30 +++++++++--------- .../views/login/RegistrationForm.js | 31 +++++++++---------- 3 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/components/views/login/CountryDropdown.js b/src/components/views/login/CountryDropdown.js index 6323b3f558..097b5eb1ec 100644 --- a/src/components/views/login/CountryDropdown.js +++ b/src/components/views/login/CountryDropdown.js @@ -38,6 +38,7 @@ export default class CountryDropdown extends React.Component { super(props); this._onSearchChange = this._onSearchChange.bind(this); this._onOptionChange = this._onOptionChange.bind(this); + this._getShortOption = this._getShortOption.bind(this); this.state = { searchQuery: '', @@ -73,6 +74,20 @@ export default class CountryDropdown extends React.Component { ); } + _getShortOption(iso2) { + if (!this.props.isSmall) { + return undefined; + } + let countryPrefix; + if (this.props.showPrefix) { + countryPrefix = '+' + COUNTRIES_BY_ISO2[iso2].prefix; + } + return + { this._flagImgForIso2(iso2) } + { countryPrefix } + ; + } + render() { const Dropdown = sdk.getComponent('elements.Dropdown'); @@ -107,11 +122,9 @@ export default class CountryDropdown extends React.Component { // values between mounting and the initial value propgating const value = this.props.value || COUNTRIES[0].iso2; - const getShortOption = this.props.isSmall ? this._flagImgForIso2 : undefined; - return {options} @@ -122,6 +135,8 @@ export default class CountryDropdown extends React.Component { CountryDropdown.propTypes = { className: React.PropTypes.string, isSmall: React.PropTypes.bool, + // if isSmall, show +44 in the selected value + showPrefix: React.PropTypes.bool, onOptionChange: React.PropTypes.func.isRequired, value: React.PropTypes.string, }; diff --git a/src/components/views/login/PasswordLogin.js b/src/components/views/login/PasswordLogin.js index 349dd0d139..46c9598751 100644 --- a/src/components/views/login/PasswordLogin.js +++ b/src/components/views/login/PasswordLogin.js @@ -149,28 +149,26 @@ class PasswordLogin extends React.Component { ; case PasswordLogin.LOGIN_FIELD_PHONE: const CountryDropdown = sdk.getComponent('views.login.CountryDropdown'); - const prefix = this.state.phonePrefix; return
+ -
-
+{prefix}
- -
; } } diff --git a/src/components/views/login/RegistrationForm.js b/src/components/views/login/RegistrationForm.js index 2bc2b8946a..e55a224531 100644 --- a/src/components/views/login/RegistrationForm.js +++ b/src/components/views/login/RegistrationForm.js @@ -314,24 +314,23 @@ module.exports = React.createClass({ const phoneSection = (
+ -
-
+{this.state.phonePrefix}
- -
);