From 29322d920a82db7671171493a52755c36ef3494e Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Sat, 6 Jul 2019 19:46:53 +0300 Subject: [PATCH] add input focus on email auth form popup --- .../auth-panel__email-login-form.tsx | 18 +++++++++++++++++- .../app/components/auth-panel/auth-panel.tsx | 13 +++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.tsx b/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.tsx index 0a4a6661..29a29462 100644 --- a/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.tsx +++ b/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.tsx @@ -6,6 +6,7 @@ import { sendEmailVerificationRequest } from '@app/common/api'; import { extractErrorMessageFromResponse } from '@app/utils/errorUtils'; import { connect } from 'preact-redux'; import { getHandleClickProps } from '@app/common/accessibility'; +import { sleep } from '@app/utils/sleep'; const mapStateToProps = () => ({ sendEmailVerification: sendEmailVerificationRequest, @@ -46,6 +47,7 @@ export class EmailLoginForm extends Component { error: null, }; + this.focus = this.focus.bind(this); this.onVerificationSubmit = this.onVerificationSubmit.bind(this); this.onSubmit = this.onSubmit.bind(this); this.onUsernameChange = this.onUsernameChange.bind(this); @@ -54,6 +56,15 @@ export class EmailLoginForm extends Component { this.goBack = this.goBack.bind(this); } + async focus() { + await sleep(100); + if (this.inputRef) { + this.inputRef.focus(); + return; + } + this.tokenRef && this.tokenRef.select(); + } + async onVerificationSubmit(e: Event) { e.preventDefault(); this.setState({ loading: true }); @@ -212,4 +223,9 @@ export class EmailLoginForm extends Component { } } -export const EmailLoginFormConnected = connect(mapStateToProps)(EmailLoginForm); +export const EmailLoginFormConnected = connect( + mapStateToProps, + null, + null, + { withRef: true } +)(EmailLoginForm); diff --git a/frontend/app/components/auth-panel/auth-panel.tsx b/frontend/app/components/auth-panel/auth-panel.tsx index 17deac92..ac494a06 100644 --- a/frontend/app/components/auth-panel/auth-panel.tsx +++ b/frontend/app/components/auth-panel/auth-panel.tsx @@ -11,7 +11,7 @@ import Dropdown, { DropdownItem } from '@app/components/dropdown'; import { Button } from '@app/components/button'; import { UserID } from './__user-id'; import { AnonymousLoginForm } from './__anonymous-login-form'; -import { EmailLoginFormConnected as EmailLoginForm } from './__email-login-form'; +import { EmailLoginForm, EmailLoginFormConnected } from './__email-login-form'; import { StoreState } from '@app/store'; export interface Props { @@ -38,6 +38,8 @@ interface State { } export class AuthPanel extends Component { + emailLoginRef?: EmailLoginForm; + constructor(props: Props) { super(props); @@ -54,6 +56,11 @@ export class AuthPanel extends Component { this.handleAnonymousLoginFormSubmut = this.handleAnonymousLoginFormSubmut.bind(this); this.handleOAuthLogin = this.handleOAuthLogin.bind(this); this.toggleUserInfoVisibility = this.toggleUserInfoVisibility.bind(this); + this.onEmailTitleClick = this.onEmailTitleClick.bind(this); + } + + onEmailTitleClick() { + this.emailLoginRef && this.emailLoginRef.focus(); } onSortChange(e: Event) { @@ -187,9 +194,11 @@ export class AuthPanel extends Component { title={PROVIDER_NAMES[provider]} titleClass="auth-panel__pseudo-link" theme={this.props.theme} + onTitleClick={this.onEmailTitleClick} > - (this.emailLoginRef = ref.getWrappedInstance())} onSignIn={this.onEmailSignIn} theme={this.props.theme} className="auth-panel__email-login-form"