Skip to content

Commit 8921260

Browse files
authored
Merge pull request #280 from devtron-labs/feat/release-channels-uat
fix: error state and auto focus for custom input
2 parents 090786f + 8d2f627 commit 8921260

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "0.2.24-beta-1",
3+
"version": "0.2.24-beta-2",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/CustomInput/CustomInput.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { CustomInputProps } from './Types'
1818
import { ReactComponent as Info } from '../../Assets/Icon/ic-info-filled-override.svg'
1919
import { ReactComponent as ErrorIcon } from '../../Assets/Icon/ic-warning.svg'
20+
import { useEffect, useRef } from 'react'
2021

2122
export 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()}

src/Common/CustomInput/Types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export interface CustomInputProps {
3737
handleOnBlur?: (e) => void
3838
readOnly?: boolean
3939
noTrim?: boolean
40-
ref?: React.LegacyRef<HTMLInputElement>
4140
onKeyPress?: (e) => void
4241
defaultValue?: string | number | ReadonlyArray<string> | undefined
4342
onKeyDown?: (e) => void

0 commit comments

Comments
 (0)