aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorMatt Goldspink <mattgoldspink1@gmail.com>2022-06-23 21:04:40 -0700
committerMatt Goldspink <mattgoldspink1@gmail.com>2022-06-23 21:04:40 -0700
commitf7eb3bbac6b4bf5333e8c8c4b4e6c2c7119a2ad4 (patch)
treeb215d73f26efad7169d247b8b2bc43bfffeae9b3 /src/web
parent1ecb866f81258d6a2319482de5dde52a1f96a13f (diff)
downloadslskd-f7eb3bbac6b4bf5333e8c8c4b4e6c2c7119a2ad4.tar.gz
Focus on username input field on load.
For some reason if I use Form.Input for the component the ref is always undefined, so had to switch it to Input. Fixes #507
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/LoginForm.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/web/src/components/LoginForm.js b/src/web/src/components/LoginForm.js
index 1be639fd..faa0fc93 100644
--- a/src/web/src/components/LoginForm.js
+++ b/src/web/src/components/LoginForm.js
@@ -1,5 +1,5 @@
-import React, { useState, useEffect, useMemo } from 'react';
-import { Button, Form, Grid, Header, Icon, Segment, Checkbox, Message } from 'semantic-ui-react';
+import React, { useState, useEffect, useMemo, useRef } from 'react';
+import { Button, Form, Input, Grid, Header, Icon, Segment, Checkbox, Message } from 'semantic-ui-react';
import Logos from './Shared/Logo';
@@ -10,6 +10,7 @@ const initialState = {
};
const LoginForm = ({ onLoginAttempt, loading, error }) => {
+ const usernameInput = useRef();
const [state, setState] = useState(initialState);
const [ready, setReady] = useState(false);
const logo = useMemo(() => Logos[Math.floor(Math.random() * Logos.length)], []);
@@ -22,6 +23,10 @@ const LoginForm = ({ onLoginAttempt, loading, error }) => {
}
}, [state]);
+ useEffect(() => {
+ usernameInput.current?.focus();
+ }, [loading]);
+
const handleChange = (field, value) => {
setState({
...state,
@@ -46,12 +51,13 @@ const LoginForm = ({ onLoginAttempt, loading, error }) => {
</Header>
<Form size='large'>
<Segment raised>
- <Form.Input
+ <Input
fluid icon='user'
iconPosition='left'
placeholder='Username'
onChange={(event) => handleChange('username', event.target.value)}
disabled={loading}
+ ref={usernameInput}
/>
<Form.Input
fluid