12
12
* License for the specific language governing permissions and limitations
13
13
* under the License.
14
14
*/
15
- import React , { useCallback , useState } from "react" ;
15
+ import React , { useCallback , useRef , useState } from "react" ;
16
16
import { getImageUrl } from "../../../utils" ;
17
17
import TooltipContainer from "../tooltip/tooltip" ;
18
18
@@ -48,6 +48,8 @@ const InputDropdown: React.FC<InputDropdownPropTypes> = (props) => {
48
48
const [ isFocused , setIsFocused ] = useState < boolean > ( false ) ;
49
49
const [ isTouched , setIsTouched ] = useState ( false ) ;
50
50
51
+ const inputRef = useRef < HTMLInputElement > ( null ) ;
52
+
51
53
const onChange = useCallback (
52
54
(
53
55
event :
@@ -64,7 +66,13 @@ const InputDropdown: React.FC<InputDropdownPropTypes> = (props) => {
64
66
const showError = props . error && ( isTouched || props . forceShowError ) ;
65
67
66
68
return (
67
- < div className = "input-field-container" >
69
+ < div
70
+ className = "input-field-container"
71
+ onBlur = { ( ) => {
72
+ setTimeout ( ( ) => {
73
+ setIsFocused ( false ) ;
74
+ } , 100 ) ;
75
+ } } >
68
76
{ props . label && (
69
77
< label
70
78
htmlFor = { props . name }
@@ -86,26 +94,44 @@ const InputDropdown: React.FC<InputDropdownPropTypes> = (props) => {
86
94
{ props . prefix }
87
95
</ div >
88
96
) }
89
- < select
97
+ < input
90
98
name = { props . name }
91
99
id = { props . name + "-text" }
92
100
onChange = { onChange }
93
101
value = { props . value }
94
102
autoFocus = { props . autofocus }
95
103
onFocus = { ( ) => setIsFocused ( true ) }
96
- onBlur = { ( ) => setIsFocused ( false ) }
97
- className = { `text-small text-black input-field ${ showError ? "input-field-error-state" : "" } ${
98
- props . size === "small" ? "input-field-small" : ""
99
- } `} >
104
+ onBlur = { ( ) => {
105
+ setTimeout ( ( ) => setIsFocused ( false ) , 200 ) ;
106
+ } }
107
+ className = { `input-dropdown text-small text-black input-field ${
108
+ showError ? "input-field-error-state" : ""
109
+ } ${ props . size === "small" ? "input-field-small" : "" } `}
110
+ type = "text"
111
+ ref = { inputRef }
112
+ />
113
+ </ div >
114
+ { isFocused && (
115
+ < div className = "input-dropdown-options" >
100
116
{ props . options . map ( ( option , index ) => (
101
- < option
117
+ < div
102
118
key = { index }
103
- value = { option } >
119
+ className = "input-dropdown-option"
120
+ onClick = { ( ) => {
121
+ if ( inputRef . current ) {
122
+ const syntheticChangeEvent = new Event ( "change" , { bubbles : true } ) ;
123
+ Object . defineProperty ( syntheticChangeEvent , "target" , {
124
+ value : { value : option , name : props . name } ,
125
+ writable : true ,
126
+ } ) ;
127
+ onChange ( syntheticChangeEvent as unknown as React . ChangeEvent < HTMLInputElement > ) ;
128
+ }
129
+ } } >
104
130
{ option }
105
- </ option >
131
+ </ div >
106
132
) ) }
107
- </ select >
108
- </ div >
133
+ </ div >
134
+ ) }
109
135
{ showError && errorPlacement === "bottom" && (
110
136
< div className = "input-field-error block-small block-error" >
111
137
< img
0 commit comments