Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit a44fcd6

Browse files
authored
Merge pull request #897 from matrix-org/luke/improve-country-dd-2
Improve phone number country dropdown for registration and login (Act. 2, Return of the Prefix)
2 parents 8ce6da1 + c44d7b6 commit a44fcd6

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
lines changed

src/components/views/login/CountryDropdown.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default class CountryDropdown extends React.Component {
3838
super(props);
3939
this._onSearchChange = this._onSearchChange.bind(this);
4040
this._onOptionChange = this._onOptionChange.bind(this);
41+
this._getShortOption = this._getShortOption.bind(this);
4142

4243
this.state = {
4344
searchQuery: '',
@@ -73,6 +74,20 @@ export default class CountryDropdown extends React.Component {
7374
);
7475
}
7576

77+
_getShortOption(iso2) {
78+
if (!this.props.isSmall) {
79+
return undefined;
80+
}
81+
let countryPrefix;
82+
if (this.props.showPrefix) {
83+
countryPrefix = '+' + COUNTRIES_BY_ISO2[iso2].prefix;
84+
}
85+
return <span>
86+
{ this._flagImgForIso2(iso2) }
87+
{ countryPrefix }
88+
</span>;
89+
}
90+
7691
render() {
7792
const Dropdown = sdk.getComponent('elements.Dropdown');
7893

@@ -107,11 +122,9 @@ export default class CountryDropdown extends React.Component {
107122
// values between mounting and the initial value propgating
108123
const value = this.props.value || COUNTRIES[0].iso2;
109124

110-
const getShortOption = this.props.isSmall ? this._flagImgForIso2 : undefined;
111-
112125
return <Dropdown className={this.props.className}
113126
onOptionChange={this._onOptionChange} onSearchChange={this._onSearchChange}
114-
menuWidth={298} getShortOption={getShortOption}
127+
menuWidth={298} getShortOption={this._getShortOption}
115128
value={value} searchEnabled={true}
116129
>
117130
{options}
@@ -122,6 +135,8 @@ export default class CountryDropdown extends React.Component {
122135
CountryDropdown.propTypes = {
123136
className: React.PropTypes.string,
124137
isSmall: React.PropTypes.bool,
138+
// if isSmall, show +44 in the selected value
139+
showPrefix: React.PropTypes.bool,
125140
onOptionChange: React.PropTypes.func.isRequired,
126141
value: React.PropTypes.string,
127142
};

src/components/views/login/PasswordLogin.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,28 +149,26 @@ class PasswordLogin extends React.Component {
149149
</div>;
150150
case PasswordLogin.LOGIN_FIELD_PHONE:
151151
const CountryDropdown = sdk.getComponent('views.login.CountryDropdown');
152-
const prefix = this.state.phonePrefix;
153152
return <div className="mx_Login_phoneSection">
154153
<CountryDropdown
155-
className="mx_Login_phoneCountry"
154+
className="mx_Login_phoneCountry mx_Login_field_prefix"
156155
ref="phone_country"
157156
onOptionChange={this.onPhoneCountryChanged}
158157
value={this.state.phoneCountry}
158+
isSmall={true}
159+
showPrefix={true}
160+
/>
161+
<input
162+
className="mx_Login_phoneNumberField mx_Login_field mx_Login_field_has_prefix"
163+
ref="phoneNumber"
164+
key="phone_input"
165+
type="text"
166+
name="phoneNumber"
167+
onChange={this.onPhoneNumberChanged}
168+
placeholder="Mobile phone number"
169+
value={this.state.phoneNumber}
170+
autoFocus
159171
/>
160-
<div className="mx_Login_field_group">
161-
<div className="mx_Login_field_prefix">+{prefix}</div>
162-
<input
163-
className="mx_Login_phoneNumberField mx_Login_field mx_Login_field_has_prefix"
164-
ref="phoneNumber"
165-
key="phone_input"
166-
type="text"
167-
name="phoneNumber"
168-
onChange={this.onPhoneNumberChanged}
169-
placeholder="Mobile phone number"
170-
value={this.state.phoneNumber}
171-
autoFocus
172-
/>
173-
</div>
174172
</div>;
175173
}
176174
}

src/components/views/login/RegistrationForm.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,24 +314,23 @@ module.exports = React.createClass({
314314
const phoneSection = (
315315
<div className="mx_Login_phoneSection">
316316
<CountryDropdown ref="phone_country" onOptionChange={this._onPhoneCountryChange}
317-
className="mx_Login_phoneCountry"
317+
className="mx_Login_phoneCountry mx_Login_field_prefix"
318318
value={this.state.phoneCountry}
319+
isSmall={true}
320+
showPrefix={true}
321+
/>
322+
<input type="text" ref="phoneNumber"
323+
placeholder="Mobile phone number (optional)"
324+
defaultValue={this.props.defaultPhoneNumber}
325+
className={this._classForField(
326+
FIELD_PHONE_NUMBER,
327+
'mx_Login_phoneNumberField',
328+
'mx_Login_field',
329+
'mx_Login_field_has_prefix'
330+
)}
331+
onBlur={function() {self.validateField(FIELD_PHONE_NUMBER);}}
332+
value={self.state.phoneNumber}
319333
/>
320-
<div className="mx_Login_field_group">
321-
<div className="mx_Login_field_prefix">+{this.state.phonePrefix}</div>
322-
<input type="text" ref="phoneNumber"
323-
placeholder="Mobile phone number (optional)"
324-
defaultValue={this.props.defaultPhoneNumber}
325-
className={this._classForField(
326-
FIELD_PHONE_NUMBER,
327-
'mx_Login_phoneNumberField',
328-
'mx_Login_field',
329-
'mx_Login_field_has_prefix'
330-
)}
331-
onBlur={function() {self.validateField(FIELD_PHONE_NUMBER);}}
332-
value={self.state.phoneNumber}
333-
/>
334-
</div>
335334
</div>
336335
);
337336

0 commit comments

Comments
 (0)