Merge pull request #3298 from benjiwheeler/join-flow-auto-focus

Join flow auto focus on first input
This commit is contained in:
Benjamin Wheeler 2019-08-27 11:37:46 -04:00 committed by GitHub
commit 9b2e7153ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 4 deletions

View file

@ -11,7 +11,7 @@ require('./formik-input.scss');
const FormikInput = ({ const FormikInput = ({
className, className,
error, error,
setRef, onSetRef,
toolTip, toolTip,
validationClassName, validationClassName,
wrapperClassName, wrapperClassName,
@ -32,7 +32,7 @@ const FormikInput = ({
className className
)} )}
/* formik uses "innerRef" to return the actual input element */ /* formik uses "innerRef" to return the actual input element */
innerRef={setRef} innerRef={onSetRef}
{...props} {...props}
/> />
{error ? ( {error ? (
@ -54,7 +54,7 @@ const FormikInput = ({
FormikInput.propTypes = { FormikInput.propTypes = {
className: PropTypes.string, className: PropTypes.string,
error: PropTypes.string, error: PropTypes.string,
setRef: PropTypes.func, onSetRef: PropTypes.func,
toolTip: PropTypes.string, toolTip: PropTypes.string,
type: PropTypes.string, type: PropTypes.string,
validationClassName: PropTypes.string, validationClassName: PropTypes.string,

View file

@ -91,12 +91,12 @@ const FormikRadioButton = ({
<FormikInput <FormikInput
className="formik-radio-input" className="formik-radio-input"
name="custom" name="custom"
setRef={onSetCustomRef}
wrapperClassName="formik-radio-input-wrapper" wrapperClassName="formik-radio-input-wrapper"
/* eslint-disable react/jsx-no-bind */ /* eslint-disable react/jsx-no-bind */
onChange={event => onSetCustom(event.target.value)} onChange={event => onSetCustom(event.target.value)}
onFocus={event => onSetCustom(event.target.value)} onFocus={event => onSetCustom(event.target.value)}
/* eslint-enable react/jsx-no-bind */ /* eslint-enable react/jsx-no-bind */
onSetRef={onSetCustomRef}
/> />
)} )}
</Field> </Field>

View file

@ -17,11 +17,19 @@ class EmailStep extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'handleSetEmailRef',
'handleValidSubmit', 'handleValidSubmit',
'validateEmail', 'validateEmail',
'validateForm' 'validateForm'
]); ]);
} }
componentDidMount () {
// automatically start with focus on username field
if (this.emailInput) this.emailInput.focus();
}
handleSetEmailRef (emailInputRef) {
this.emailInput = emailInputRef;
}
validateEmail (email) { validateEmail (email) {
if (!email) return this.props.intl.formatMessage({id: 'general.required'}); if (!email) return this.props.intl.formatMessage({id: 'general.required'});
const isValidLocally = emailValidator.validate(email); const isValidLocally = emailValidator.validate(email);
@ -99,6 +107,7 @@ class EmailStep extends React.Component {
onBlur={() => validateField('email')} onBlur={() => validateField('email')}
onFocus={() => setFieldError('email', null)} onFocus={() => setFieldError('email', null)}
/* eslint-enable react/jsx-no-bind */ /* eslint-enable react/jsx-no-bind */
onSetRef={this.handleSetEmailRef}
/> />
<div className="join-flow-email-checkbox-row"> <div className="join-flow-email-checkbox-row">
<FormikCheckbox <FormikCheckbox

View file

@ -22,6 +22,7 @@ class UsernameStep extends React.Component {
bindAll(this, [ bindAll(this, [
'handleChangeShowPassword', 'handleChangeShowPassword',
'handleFocused', 'handleFocused',
'handleSetUsernameRef',
'handleValidSubmit', 'handleValidSubmit',
'validatePasswordIfPresent', 'validatePasswordIfPresent',
'validatePasswordConfirmIfPresent', 'validatePasswordConfirmIfPresent',
@ -33,6 +34,10 @@ class UsernameStep extends React.Component {
showPassword: false showPassword: false
}; };
} }
componentDidMount () {
// automatically start with focus on username field
if (this.usernameInput) this.usernameInput.focus();
}
handleChangeShowPassword () { handleChangeShowPassword () {
this.setState({showPassword: !this.state.showPassword}); this.setState({showPassword: !this.state.showPassword});
} }
@ -41,6 +46,9 @@ class UsernameStep extends React.Component {
handleFocused (fieldName) { handleFocused (fieldName) {
this.setState({focused: fieldName}); this.setState({focused: fieldName});
} }
handleSetUsernameRef (usernameInputRef) {
this.usernameInput = usernameInputRef;
}
// we allow username to be empty on blur, since you might not have typed anything yet // we allow username to be empty on blur, since you might not have typed anything yet
validateUsernameIfPresent (username) { validateUsernameIfPresent (username) {
if (!username) return null; // skip validation if username is blank; null indicates valid if (!username) return null; // skip validation if username is blank; null indicates valid
@ -160,6 +168,7 @@ class UsernameStep extends React.Component {
}} }}
onFocus={() => this.handleFocused('username')} onFocus={() => this.handleFocused('username')}
/* eslint-enable react/jsx-no-bind */ /* eslint-enable react/jsx-no-bind */
onSetRef={this.handleSetUsernameRef}
/> />
<div className="join-flow-password-section"> <div className="join-flow-password-section">
<div className="join-flow-input-title"> <div className="join-flow-input-title">