import * as React from "react"; import { BlurableInput, Col, Widget, WidgetBody, WidgetHeader, Row, } from "../ui/index"; import { BlurablePassword } from "../ui/blurable_password"; import { t } from "../i18next_wrapper"; import { updatePageInfo } from "../util"; export interface LoginProps { /** Attributes */ email: string | undefined; /** Callbacks */ onToggleForgotPassword(): void; onSubmit(e: React.FormEvent): void; onEmailChange(e: React.SyntheticEvent): void; onLoginPasswordChange(e: React.SyntheticEvent): void; } export class Login extends React.Component { /** PROBLEM: only updates when when `blur` event happens. * * No update when you push return key- that's a submit event. * SOLUTION: Intercept the `submit` event and forcibly focus on a hidden * input control, thereby triggering the blur event across all * fields. */ private hiddenFieldRef: HTMLElement | undefined = undefined; /** CSS to hide the fake input field used to change focus. */ HIDE_ME = { background: "transparent", border: "none", display: "node" }; render() { const { email, onEmailChange, onSubmit, onLoginPasswordChange, onToggleForgotPassword, } = this.props; updatePageInfo("login"); return
{ e.persist(); e.preventDefault(); /** Force focus on fake input. Triggers blur on all inputs. */ this.hiddenFieldRef && this.hiddenFieldRef.focus(); /** Give React time to update stuff before triggering callback. */ setTimeout(() => onSubmit(e), 3); }}>
x && (this.hiddenFieldRef = x)} />
{t("Forgot password?")}
; } }