File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -241,6 +241,17 @@ export const Credentials = React.forwardRef(
241241 initialValues ,
242242 )
243243
244+ const inputRefs = useRef ( { } )
245+
246+ useEffect ( ( ) => {
247+ for ( const field of credentials ) {
248+ if ( errors [ field . field_name ] ) {
249+ inputRefs . current [ field . field_name ] ?. focus ( )
250+ break
251+ }
252+ }
253+ } , [ errors ] )
254+
244255 function attemptConnect ( ) {
245256 const credentialsPayload = credentials . map ( ( credential ) => {
246257 return {
@@ -444,7 +455,13 @@ export const Credentials = React.forwardRef(
444455 errors [ field . field_name ]
445456 }
446457 id = { field . field_name }
447- inputProps = { { 'aria-label' : field . label } }
458+ inputProps = { {
459+ 'aria-label' : field . label ,
460+ 'aria-describedby' : errors [ field . field_name ]
461+ ? `${ field . field_name } -error`
462+ : undefined ,
463+ } }
464+ inputRef = { ( el ) => ( inputRefs . current [ field . field_name ] = el ) }
448465 label = { field . label }
449466 name = { field . field_name }
450467 onBlur = { handleBlur }
@@ -469,7 +486,13 @@ export const Credentials = React.forwardRef(
469486 fullWidth = { true }
470487 helperText = { errors [ field . field_name ] }
471488 id = { field . field_name }
472- inputProps = { { 'aria-label' : __ ( 'Enter your %1' , field . label ) } }
489+ inputProps = { {
490+ 'aria-label' : __ ( 'Enter your %1' , field . label ) ,
491+ 'aria-describedby' : errors [ field . field_name ]
492+ ? `${ field . field_name } -error`
493+ : undefined ,
494+ } }
495+ inputRef = { ( el ) => ( inputRefs . current [ field . field_name ] = el ) }
473496 label = { field . label }
474497 name = { field . field_name }
475498 onChange = { handleUserNameTextChange }
You can’t perform that action at this time.
0 commit comments