1717import { CustomInputProps } from './Types'
1818import { ReactComponent as Info } from '../../Assets/Icon/ic-info-filled-override.svg'
1919import { ReactComponent as ErrorIcon } from '../../Assets/Icon/ic-warning.svg'
20+ import { useEffect , useRef } from 'react'
2021
2122export const CustomInput = ( {
2223 name,
@@ -39,7 +40,6 @@ export const CustomInput = ({
3940 handleOnBlur,
4041 readOnly = false ,
4142 noTrim = false ,
42- ref,
4343 onKeyPress,
4444 defaultValue,
4545 onKeyDown,
@@ -48,6 +48,17 @@ export const CustomInput = ({
4848 inputWrapClassName = '' ,
4949 inputProps = { } ,
5050} : CustomInputProps ) => {
51+ const inputRef = useRef < HTMLInputElement > ( )
52+
53+ useEffect ( ( ) => {
54+ setTimeout ( ( ) => {
55+ // Added timeout to ensure the autofocus code is executed post the re-renders
56+ if ( inputRef . current && autoFocus ) {
57+ inputRef . current . focus ( )
58+ }
59+ } , 100 )
60+ } , [ autoFocus ] )
61+
5162 function handleError ( error : any ) : any [ ] {
5263 if ( ! Array . isArray ( error ) ) {
5364 return [ error ]
@@ -68,9 +79,9 @@ export const CustomInput = ({
6879 }
6980
7081 const renderFormErrorWithIcon = ( error : string ) => (
71- < div className = "form__error " key = { error } >
72- < ErrorIcon className = "form__icon form__icon--error" />
73- { error }
82+ < div className = "flex left mt-4 mb-4 dc__gap-4 cr-5 fs-11 lh-16 fw-4 " key = { error } >
83+ < ErrorIcon className = "icon-dim-16 p-1 form__icon--error dc__align-self-start dc__no-shrink " />
84+ < span > { error } </ span >
7485 { error && typeof additionalErrorInfo === 'function' && additionalErrorInfo ( ) }
7586 </ div >
7687 )
@@ -124,13 +135,13 @@ export const CustomInput = ({
124135 tabIndex = { tabIndex }
125136 autoFocus = { autoFocus }
126137 readOnly = { readOnly }
127- ref = { ref }
128138 onKeyPress = { onKeyPress }
129139 defaultValue = { defaultValue }
130140 onKeyDown = { onKeyDown }
131141 required = { required }
132142 // Will be passing other props like other data attributes etc from inputProps
133143 { ...inputProps }
144+ ref = { inputRef }
134145 />
135146
136147 { getInputError ( ) }
0 commit comments