@platformatic/ui-components 0.8.6 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -28,8 +28,10 @@ function Select ({
|
|
|
28
28
|
backgroundColor = WHITE,
|
|
29
29
|
inputTextClassName = '',
|
|
30
30
|
beforeIcon = {},
|
|
31
|
-
paddingClass = ''
|
|
31
|
+
paddingClass = '',
|
|
32
|
+
handleClickOutside = false
|
|
32
33
|
}) {
|
|
34
|
+
const wrapperRef = useRef(null)
|
|
33
35
|
const inputRef = useRef()
|
|
34
36
|
const [showOptions, setShowOptions] = useState(false)
|
|
35
37
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -105,6 +107,22 @@ function Select ({
|
|
|
105
107
|
}
|
|
106
108
|
}, [value])
|
|
107
109
|
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (showOptions && handleClickOutside) {
|
|
112
|
+
function innerHandleClickOutside (event) {
|
|
113
|
+
if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
|
|
114
|
+
setShowOptions(false)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Bind the event listener
|
|
118
|
+
document.addEventListener('mousedown', innerHandleClickOutside)
|
|
119
|
+
return () => {
|
|
120
|
+
// Unbind the event listener on clean up
|
|
121
|
+
document.removeEventListener('mousedown', innerHandleClickOutside)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}, [handleClickOutside, showOptions])
|
|
125
|
+
|
|
108
126
|
useEffect(() => {
|
|
109
127
|
if (disabled) {
|
|
110
128
|
const className = normalClassName() + ' ' + commonStyles['apply-opacity-30']
|
|
@@ -170,7 +188,7 @@ function Select ({
|
|
|
170
188
|
}
|
|
171
189
|
|
|
172
190
|
return (
|
|
173
|
-
<div className={containerClassName} {...dataProps}>
|
|
191
|
+
<div className={containerClassName} {...dataProps} ref={wrapperRef}>
|
|
174
192
|
<div className={wrapperClassName}>
|
|
175
193
|
{beforeIcon?.iconName && getBeforeIcon()}
|
|
176
194
|
<input type='text' name={name} value={value} className={inputClassName} ref={inputRef} disabled={disabled} placeholder={placeholder} onFocus={() => handleFocus()} onBlur={(e) => handleBlur(e)} readOnly />
|
|
@@ -285,7 +303,11 @@ Select.propTypes = {
|
|
|
285
303
|
/**
|
|
286
304
|
* paddingClass
|
|
287
305
|
*/
|
|
288
|
-
paddingClass: PropTypes.string
|
|
306
|
+
paddingClass: PropTypes.string,
|
|
307
|
+
/**
|
|
308
|
+
* handleClickOutside
|
|
309
|
+
*/
|
|
310
|
+
handleClickOutside: PropTypes.bool
|
|
289
311
|
}
|
|
290
312
|
|
|
291
313
|
export default Select
|