Skip to content

Commit c9c4b9f

Browse files
committed
Set focus to password field when login_hint is given
To improve usability when the RP provides the login_hint parameter, this change automatically sets the input focus to the password field when a login_hint is provided.
1 parent 50cbe01 commit c9c4b9f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

identifier/src/containers/Login/Login.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo } from 'react';
1+
import React, { useEffect, useMemo, useRef } from 'react';
22
import PropTypes from 'prop-types';
33
import { connect } from 'react-redux';
44

@@ -73,6 +73,7 @@ function Login(props) {
7373
const { t } = useTranslation();
7474

7575
const [showPassword, setShowPassword] = React.useState(false);
76+
const passwordInputRef = useRef();
7677

7778
useEffect(() => {
7879
if (hello && hello.state && history.action !== 'PUSH') {
@@ -89,7 +90,10 @@ function Login(props) {
8990
if (query && query.login_hint) {
9091
if (isEmail(query.login_hint) || isEmail(`${query.login_hint}@example.com`)) {
9192
dispatch(updateInput("username", query.login_hint));
92-
}
93+
setTimeout(() => {
94+
passwordInputRef.current.focus();
95+
}, 0);
96+
}
9397
}
9498
}, [ /* no dependencies */ ]); // eslint-disable-line react-hooks/exhaustive-deps
9599

@@ -148,6 +152,7 @@ function Login(props) {
148152
className={classes.usernameInputField}
149153
/>
150154
<TextField
155+
inputRef={passwordInputRef}
151156
type={showPassword ? "text" : "password"}
152157
label={t("konnect.login.passwordField.label", "Password")}
153158
error={!!errors.password}

0 commit comments

Comments
 (0)