@@ -7,10 +7,14 @@ import { RGBA, TEXT_INPUT_STYLE } from 'twenty-ui';
7
7
import { useRegisterInputEvents } from '@/object-record/record-field/meta-types/input/hooks/useRegisterInputEvents' ;
8
8
import { useCombinedRefs } from '~/hooks/useCombinedRefs' ;
9
9
10
- const StyledInput = styled . input < { withRightComponent ?: boolean } > `
10
+ const StyledInput = styled . input < {
11
+ withRightComponent ?: boolean ;
12
+ hasError ?: boolean ;
13
+ } > `
11
14
${ TEXT_INPUT_STYLE }
12
15
13
- border: 1px solid ${ ( { theme } ) => theme . border . color . medium } ;
16
+ border: 1px solid ${ ( { theme, hasError } ) =>
17
+ hasError ? theme . border . color . danger : theme . border . color . medium } ;
14
18
border-radius: ${ ( { theme } ) => theme . border . radius . sm } ;
15
19
box-sizing: border-box;
16
20
font-weight: ${ ( { theme } ) => theme . font . weight . medium } ;
@@ -19,8 +23,10 @@ const StyledInput = styled.input<{ withRightComponent?: boolean }>`
19
23
width: 100%;
20
24
21
25
&:focus {
22
- border-color: ${ ( { theme } ) => theme . color . blue } ;
23
- box-shadow: 0px 0px 0px 3px ${ ( { theme } ) => RGBA ( theme . color . blue , 0.1 ) } ;
26
+ ${ ( { theme, hasError = false } ) => {
27
+ if ( hasError ) return '' ;
28
+ return `box-shadow: 0px 0px 0px 3px ${ RGBA ( theme . color . blue , 0.1 ) } ` ;
29
+ } } ;
24
30
}
25
31
26
32
${ ( { withRightComponent } ) =>
@@ -44,6 +50,12 @@ const StyledRightContainer = styled.div`
44
50
transform: translateY(-50%);
45
51
` ;
46
52
53
+ const StyledErrorDiv = styled . div `
54
+ color: ${ ( { theme } ) => theme . color . red } ;
55
+ padding: 0 ${ ( { theme } ) => theme . spacing ( 2 ) }
56
+ ${ ( { theme } ) => theme . spacing ( 1 ) } ;
57
+ ` ;
58
+
47
59
type HTMLInputProps = InputHTMLAttributes < HTMLInputElement > ;
48
60
49
61
export type DropdownMenuInputProps = HTMLInputProps & {
@@ -60,6 +72,8 @@ export type DropdownMenuInputProps = HTMLInputProps & {
60
72
autoFocus : HTMLInputProps [ 'autoFocus' ] ;
61
73
placeholder : HTMLInputProps [ 'placeholder' ] ;
62
74
} ) => React . ReactNode ;
75
+ error ?: string | null ;
76
+ hasError ?: boolean ;
63
77
} ;
64
78
65
79
export const DropdownMenuInput = forwardRef <
@@ -81,6 +95,8 @@ export const DropdownMenuInput = forwardRef<
81
95
onTab,
82
96
rightComponent,
83
97
renderInput,
98
+ error = '' ,
99
+ hasError = false ,
84
100
} ,
85
101
ref ,
86
102
) => {
@@ -99,28 +115,32 @@ export const DropdownMenuInput = forwardRef<
99
115
} ) ;
100
116
101
117
return (
102
- < StyledInputContainer className = { className } >
103
- { renderInput ? (
104
- renderInput ( {
105
- value,
106
- onChange,
107
- autoFocus,
108
- placeholder,
109
- } )
110
- ) : (
111
- < StyledInput
112
- autoFocus = { autoFocus }
113
- value = { value }
114
- placeholder = { placeholder }
115
- onChange = { onChange }
116
- ref = { combinedRef }
117
- withRightComponent = { ! ! rightComponent }
118
- />
119
- ) }
120
- { ! ! rightComponent && (
121
- < StyledRightContainer > { rightComponent } </ StyledRightContainer >
122
- ) }
123
- </ StyledInputContainer >
118
+ < >
119
+ < StyledInputContainer className = { className } >
120
+ { renderInput ? (
121
+ renderInput ( {
122
+ value,
123
+ onChange,
124
+ autoFocus,
125
+ placeholder,
126
+ } )
127
+ ) : (
128
+ < StyledInput
129
+ hasError = { hasError }
130
+ autoFocus = { autoFocus }
131
+ value = { value }
132
+ placeholder = { placeholder }
133
+ onChange = { onChange }
134
+ ref = { combinedRef }
135
+ withRightComponent = { ! ! rightComponent }
136
+ />
137
+ ) }
138
+ { ! ! rightComponent && (
139
+ < StyledRightContainer > { rightComponent } </ StyledRightContainer >
140
+ ) }
141
+ </ StyledInputContainer >
142
+ { error && < StyledErrorDiv > { error } </ StyledErrorDiv > }
143
+ </ >
124
144
) ;
125
145
} ,
126
146
) ;
0 commit comments