@@ -38,6 +38,8 @@ const reducer = (state, action) => {
3838
3939export const VerifyDeposits = ( { microdeposit, onSuccess } ) => {
4040 const containerRef = useRef ( null )
41+ const firstInputRef = useRef ( null )
42+ const secondInputRef = useRef ( null )
4143 useAnalyticsPath ( ...PageviewInfo . CONNECT_MICRODEPOSITS_VERIFY_DEPOSITS )
4244 const { api } = useApi ( )
4345 const initialForm = { firstAmount : '' , secondAmount : '' }
@@ -84,6 +86,14 @@ export const VerifyDeposits = ({ microdeposit, onSuccess }) => {
8486 return ( ) => subscription . unsubscribe ( )
8587 } , [ state . isSubmitting ] )
8688
89+ useEffect ( ( ) => {
90+ if ( errors . firstAmount ) {
91+ firstInputRef . current . focus ( )
92+ } else if ( errors . secondAmount ) {
93+ secondInputRef . current . focus ( )
94+ }
95+ } , [ errors ] )
96+
8797 return (
8898 < div ref = { containerRef } >
8999 < SlideDown >
@@ -134,7 +144,11 @@ export const VerifyDeposits = ({ microdeposit, onSuccess }) => {
134144 error = { ! ! errors . firstAmount }
135145 helperText = { errors . firstAmount }
136146 id = { schema . firstAmount . label }
137- inputProps = { { 'data-test' : 'amount-1-input' } }
147+ inputProps = { {
148+ 'data-test' : 'amount-1-input' ,
149+ 'aria-describedby' : errors . firstAmount ? 'firstAmount-error' : undefined ,
150+ } }
151+ inputRef = { firstInputRef }
138152 label = { schema . firstAmount . label }
139153 name = "firstAmount"
140154 onChange = { handleTextInputChange }
@@ -149,7 +163,11 @@ export const VerifyDeposits = ({ microdeposit, onSuccess }) => {
149163 error = { ! ! errors . secondAmount }
150164 helperText = { errors . secondAmount }
151165 id = { schema . secondAmount . label }
152- inputProps = { { 'data-test' : 'amount-2-input' } }
166+ inputProps = { {
167+ 'data-test' : 'amount-2-input' ,
168+ 'aria-describedby' : errors . secondAmount ? 'secondAmount-error' : undefined ,
169+ } }
170+ inputRef = { secondInputRef }
153171 label = { schema . secondAmount . label }
154172 name = "secondAmount"
155173 onChange = { handleTextInputChange }
0 commit comments