@codeleap/web 3.9.0 → 3.10.1
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
|
@@ -168,6 +168,8 @@ const defaultProps: Partial<SelectProps> = {
|
|
|
168
168
|
itemProps: {} as ButtonProps,
|
|
169
169
|
loadingIndicatorSize: 20,
|
|
170
170
|
options: [],
|
|
171
|
+
loadInitialValue: false,
|
|
172
|
+
loadingMessage: 'loading...',
|
|
171
173
|
}
|
|
172
174
|
|
|
173
175
|
export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
@@ -195,6 +197,7 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
195
197
|
loadOptions,
|
|
196
198
|
multiple,
|
|
197
199
|
limit = null,
|
|
200
|
+
loadInitialValue,
|
|
198
201
|
focused,
|
|
199
202
|
_error,
|
|
200
203
|
renderItem: OptionComponent = null,
|
|
@@ -221,6 +224,7 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
221
224
|
loadingIndicatorSize,
|
|
222
225
|
selectedOption: _selectedOption,
|
|
223
226
|
setSelectedOption: _setSelectedOption,
|
|
227
|
+
loadingMessage,
|
|
224
228
|
...otherProps
|
|
225
229
|
} = selectProps
|
|
226
230
|
|
|
@@ -229,10 +233,14 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
229
233
|
|
|
230
234
|
const hasSelectedOptionState = !TypeGuards.isNil(_selectedOption) && TypeGuards.isFunction(_setSelectedOption)
|
|
231
235
|
|
|
232
|
-
const
|
|
236
|
+
const initialValue = (loadInitialValue && !TypeGuards.isNil(options))
|
|
237
|
+
? options?.find((option) => option?.value === value)
|
|
238
|
+
: value
|
|
233
239
|
|
|
234
|
-
const [
|
|
240
|
+
const [selectedOption, setSelectedOption] = hasSelectedOptionState ? [_selectedOption, _setSelectedOption] : useState(initialValue ?? value)
|
|
235
241
|
|
|
242
|
+
const [_isFocused, setIsFocused] = useState(false)
|
|
243
|
+
const [loadedOptions, setLoadedOptions] = useState(false)
|
|
236
244
|
const [keyDownActive, setKeyDownActive] = useState(false)
|
|
237
245
|
|
|
238
246
|
const isFocused = _isFocused || focused
|
|
@@ -276,6 +284,13 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
276
284
|
return options
|
|
277
285
|
})
|
|
278
286
|
|
|
287
|
+
if (loadInitialValue && !TypeGuards.isNil(_options) && !loadedOptions) {
|
|
288
|
+
const _initialValue = _options?.find?.((option) => option?.value === value)
|
|
289
|
+
if (!!_initialValue) setSelectedOption(_initialValue)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
setLoadedOptions(true)
|
|
293
|
+
|
|
279
294
|
return _options
|
|
280
295
|
} catch (err) {
|
|
281
296
|
onLoadOptionsError?.(err)
|
|
@@ -401,7 +416,7 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
401
416
|
ref={innerInputRef}
|
|
402
417
|
closeMenuOnSelect={closeOnSelect}
|
|
403
418
|
menuPortalTarget={innerWrapperRef.current}
|
|
404
|
-
placeholder={placeholder}
|
|
419
|
+
placeholder={(loadOptionsOnMount && !loadedOptions) ? loadingMessage : placeholder}
|
|
405
420
|
isDisabled={isDisabled}
|
|
406
421
|
isClearable={clearable}
|
|
407
422
|
isSearchable={searchable}
|
|
@@ -93,6 +93,8 @@ export type SelectProps<T = any, Multi extends boolean = false> = React.PropsWit
|
|
|
93
93
|
itemProps?: ButtonProps
|
|
94
94
|
loadingIndicatorSize?: number
|
|
95
95
|
limit?: number
|
|
96
|
+
loadInitialValue?: boolean
|
|
97
|
+
loadingMessage?: string
|
|
96
98
|
selectedOption?: ReactSelectProps<T>['value']
|
|
97
99
|
setSelectedOption?: ReactSelectProps<T>['onValueChange']
|
|
98
100
|
} & Omit<
|