From 3072cd4bffd6c761c7c0ad760fc85efc7bc9ff6f Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Mon, 30 Mar 2020 11:43:43 -0300 Subject: [PATCH] 16212: Set focus on username input element. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/views-components/login-form/login-form.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/views-components/login-form/login-form.tsx b/src/views-components/login-form/login-form.tsx index 404c91ff..80d59995 100644 --- a/src/views-components/login-form/login-form.tsx +++ b/src/views-components/login-form/login-form.tsx @@ -3,7 +3,7 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { useState, useEffect } from 'react'; +import { useState, useEffect, useRef } from 'react'; import { withStyles, WithStyles, StyleRulesCallback } from '@material-ui/core/styles'; import CircularProgress from '@material-ui/core/CircularProgress'; import { Button, Card, CardContent, TextField, CardActions } from '@material-ui/core'; @@ -47,6 +47,7 @@ interface LoginFormProps { export const LoginForm = withStyles(styles)( ({ handleSubmit, classes }: LoginFormProps & WithStyles) => { + const userInput = useRef(null); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [isButtonDisabled, setIsButtonDisabled] = useState(true); @@ -64,6 +65,11 @@ export const LoginForm = withStyles(styles)( } }, [username, password]); + // This only run once after render. + useEffect(() => { + userInput.current!.focus(); + }, []); + const handleLogin = () => { setSubmitting(true); handleSubmit(username, password) @@ -96,6 +102,7 @@ export const LoginForm = withStyles(styles)(