A few minor fixes

This commit is contained in:
Ben Gotow 2016-05-25 13:26:46 -07:00
parent 7110217fd4
commit dfea0a9861
4 changed files with 41 additions and 44 deletions

View file

@ -146,9 +146,9 @@ export function accountInfoWithIMAPAutocompletions(existingAccountInfo) {
const defaults = {
imap_host: template.imap_host,
imap_port: template.imap_port || 993,
imap_username: usernameWithFormat(template.smtp_user_format),
imap_username: usernameWithFormat(template.imap_user_format),
imap_password: existingAccountInfo.password,
smtp_host: template.imap_host,
smtp_host: template.smtp_host,
smtp_port: template.smtp_port || 587,
smtp_username: usernameWithFormat(template.smtp_user_format),
smtp_password: existingAccountInfo.password,

View file

@ -1,29 +0,0 @@
import React from 'react';
import ReactDOM from 'react-dom';
export default class AutofocusContainer extends React.Component {
static propTypes = {
children: React.PropTypes.children,
}
componentDidMount() {
this._applyFocus();
}
componentDidUpdate() {
this._applyFocus();
}
_applyFocus() {
const firstInput = ReactDOM.findDOMNode(this).querySelector('input');
const anyInputFocused = document.activeElement && document.activeElement.nodeName === 'INPUT';
if (firstInput && !anyInputFocused) {
firstInput.focus();
}
}
render() {
return (<div>{this.props.children}</div>);
}
}

View file

@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import {RetinaImg} from 'nylas-component-kit';
import {Actions} from 'nylas-exports';
import OnboardingActions from '../onboarding-actions';
import AutofocusContainer from '../autofocus-container';
import {runAuthRequest} from '../account-helpers';
import FormErrorMessage from '../form-error-message';
import AccountTypes from '../account-types'
@ -26,6 +26,34 @@ const CreatePageForForm = (FormComponent) => {
}, FormComponent.validateAccountInfo(this.props.accountInfo));
}
componentDidMount() {
this._applyFocus();
}
componentDidUpdate() {
this._applyFocus();
}
_applyFocus() {
const anyInputFocused = document.activeElement && document.activeElement.nodeName === 'INPUT';
if (anyInputFocused) {
return;
}
const inputs = Array.from(ReactDOM.findDOMNode(this).querySelectorAll('input'));
if (inputs.length === 0) {
return;
}
for (const input of inputs) {
if (input.value === '') {
input.focus();
return;
}
}
inputs[0].focus();
}
onFieldChange = (event) => {
const changes = {};
changes[event.target.id] = event.target.value;
@ -135,17 +163,15 @@ const CreatePageForForm = (FormComponent) => {
message={errorMessage}
empty={FormComponent.subtitleLabel(AccountType)}
/>
<AutofocusContainer>
<FormComponent
ref="form"
accountInfo={accountInfo}
errorFieldNames={errorFieldNames}
submitting={submitting}
onFieldChange={this.onFieldChange}
onFieldKeyPress={this.onFieldKeyPress}
onConnect={this.onConnect}
/>
</AutofocusContainer>
<FormComponent
ref="form"
accountInfo={accountInfo}
errorFieldNames={errorFieldNames}
submitting={submitting}
onFieldChange={this.onFieldChange}
onFieldKeyPress={this.onFieldKeyPress}
onConnect={this.onConnect}
/>
<div>
<div className="btn btn-large btn-gradient" onClick={this.onBack}>Back</div>
{this._renderButton()}

View file

@ -69,7 +69,7 @@ class AccountIMAPSettingsForm extends React.Component {
id={`ssl_required`}
className={(accountInfo.imap_host && errorFieldNames.includes(`ssl_required`)) ? 'error' : ''}
disabled={submitting}
value={accountInfo[`ssl_required`] || ''}
checked={accountInfo[`ssl_required`] || false}
onKeyPress={onFieldKeyPress}
onChange={onFieldChange}
/>