Skip to content

Commit

Permalink
Merge pull request Expensify#24026 from hoangzinh/df/23797
Browse files Browse the repository at this point in the history
Fix - Login field is focused when sign out in small screen devices
  • Loading branch information
PauloGasparSv authored Aug 5, 2023
2 parents be9c400 + 283cb9d commit 4230f28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/hooks/usePrevious.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {useEffect, useRef} from 'react';
* @returns {*}
*/
export default function usePrevious(value) {
const ref = useRef();
const ref = useRef(value);
useEffect(() => {
ref.current = value;
}, [value]);
Expand Down
8 changes: 6 additions & 2 deletions src/pages/signin/LoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import isInputAutoFilled from '../../libs/isInputAutoFilled';
import * as PolicyUtils from '../../libs/PolicyUtils';
import Log from '../../libs/Log';
import withNavigationFocus, {withNavigationFocusPropTypes} from '../../components/withNavigationFocus';
import usePrevious from '../../hooks/usePrevious';

const propTypes = {
/** Should we dismiss the keyboard when transitioning away from the page? */
Expand Down Expand Up @@ -81,6 +82,7 @@ function LoginForm(props) {
const input = useRef();
const [login, setLogin] = useState('');
const [formError, setFormError] = useState(false);
const prevIsVisible = usePrevious(props.isVisible);

const {translate} = props;

Expand Down Expand Up @@ -166,11 +168,13 @@ function LoginForm(props) {
if (props.blurOnSubmit) {
input.current.blur();
}
if (!input.current || !props.isVisible) {

// Only focus the input if the form becomes visible again, to prevent the keyboard from automatically opening on touchscreen devices after signing out
if (!input.current || prevIsVisible || !props.isVisible) {
return;
}
input.current.focus();
}, [props.blurOnSubmit, props.isVisible, input]);
}, [props.blurOnSubmit, props.isVisible, prevIsVisible]);

const formErrorText = useMemo(() => (formError ? translate(formError) : ''), [formError, translate]);
const serverErrorText = useMemo(() => ErrorUtils.getLatestErrorMessage(props.account), [props.account]);
Expand Down

0 comments on commit 4230f28

Please sign in to comment.