From 73640ba4e2a3ce4d157713c44b03eef0013e4e19 Mon Sep 17 00:00:00 2001 From: Nikhil Mohite Date: Fri, 24 Nov 2023 13:29:13 +0530 Subject: [PATCH] Ensure focus is not changed to ssh tunnel input box when user explicitly focus in server password edit box --- .../static/js/Dialogs/ConnectServerContent.jsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/web/pgadmin/static/js/Dialogs/ConnectServerContent.jsx b/web/pgadmin/static/js/Dialogs/ConnectServerContent.jsx index a9998047137..4822b9f1f57 100644 --- a/web/pgadmin/static/js/Dialogs/ConnectServerContent.jsx +++ b/web/pgadmin/static/js/Dialogs/ConnectServerContent.jsx @@ -7,7 +7,7 @@ // ////////////////////////////////////////////////////////////// -import React, { useState, useRef, useEffect } from 'react'; +import React, { useState, useRef, useEffect, useLayoutEffect } from 'react'; import gettext from 'sources/gettext'; import { Box } from '@material-ui/core'; import { DefaultButton, PrimaryButton } from '../components/Buttons'; @@ -21,6 +21,7 @@ export default function ConnectServerContent({closeModal, data, onOK, setHeight} const classes = useModalStyles(); const containerRef = useRef(); const firstEleRef = useRef(); + const [firstElState, setFirstElState] = useState(); const okBtnRef = useRef(); const [formData, setFormData] = useState({ tunnel_password: '', @@ -44,10 +45,11 @@ export default function ConnectServerContent({closeModal, data, onOK, setHeight} } }; - useEffect(()=>{ - setTimeout(()=>{ - firstEleRef.current && firstEleRef.current.focus(); - }, 350); + + useLayoutEffect(()=>{ + if(!firstElState){ + firstEleRef.current && firstEleRef.current.focus(), setFirstElState(firstEleRef.current); + } }, [firstEleRef.current]); useEffect(()=>{