@@ -95,6 +95,7 @@ export const FormPasswordWithBalloons = ({
9595 useState < string > ( ) ;
9696 const [ srOnlyConfirmPwdFeedbackMessage , setSROnlyConfirmPwdFeedbackMessage ] =
9797 useState < string > ( ) ;
98+ const [ emitEngageEvent , setEmitEngageEvent ] = useState < boolean > ( false ) ;
9899
99100 const ftlMsgResolver = useFtlMsgResolver ( ) ;
100101 const localizedPasswordMatchError = ftlMsgResolver . getMsg (
@@ -154,13 +155,31 @@ export const FormPasswordWithBalloons = ({
154155 setSROnlyConfirmPwdFeedbackMessage ( '' ) ;
155156 setPasswordMatchErrorText ( '' ) ;
156157 if ( ! hasNewPwdFocused ) {
157- if ( onFocusMetricsEvent ) {
158- onFocusMetricsEvent ( ) ;
159- }
160158 setHasNewPwdFocused ( true ) ;
161159 }
162160 } ;
163161
162+ // We are currently on React form hook V6 and this version
163+ // does not expose any focus methods. Upgrading is major refactor
164+ // so instead we pass an optional `inputRefDOM` that can
165+ // trigger focus and click events.
166+ const newPasswordRef = useRef < HTMLInputElement > ( null ) ;
167+
168+ // Auto-focus the new password input on mount
169+ useEffect ( ( ) => {
170+ if ( newPasswordRef . current ) {
171+ newPasswordRef . current . focus ( ) ;
172+ newPasswordRef . current . click ( ) ;
173+ }
174+ } , [ ] ) ;
175+
176+ useEffect ( ( ) => {
177+ if ( hasUserTakenAction && onFocusMetricsEvent && ! emitEngageEvent ) {
178+ onFocusMetricsEvent ( ) ;
179+ setEmitEngageEvent ( true ) ;
180+ }
181+ } , [ hasUserTakenAction , onFocusMetricsEvent , emitEngageEvent ] ) ;
182+
164183 const onNewPwdBlur = ( ) => {
165184 // do not hide the password strength balloon if there are errors in the new password
166185 if ( ! errors . newPassword ) {
@@ -326,6 +345,7 @@ export const FormPasswordWithBalloons = ({
326345 } ,
327346 } ,
328347 } ) }
348+ inputRefDOM = { newPasswordRef }
329349 prefixDataTestId = "new-password"
330350 aria-describedby = "password-requirements"
331351 />
0 commit comments