File tree 4 files changed +12
-11
lines changed
4 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ export const RemoteDataSetExample2 = memo((props: Omit<IAutocompleteDropdownProp
49
49
< AutocompleteDropdown
50
50
ref = { searchRef }
51
51
controller = { dropdownController }
52
- // initialValue={'1'}
52
+ initialValue = { { id : '1' , title : 'Initial val' } }
53
53
// direction={Platform.select({ ios: 'down' })}
54
54
dataSet = { suggestionsList }
55
55
onChangeText = { getSuggestions }
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ export const RemoteDataSetExample3 = memo(() => {
43
43
< AutocompleteDropdown
44
44
ref = { searchRef }
45
45
closeOnBlur = { false }
46
+ // initialValue={{ id: '1', title: 'Initial val' }}
46
47
// direction={Platform.select({ ios: 'down' })}
47
48
controller = { controller => {
48
49
dropdownController . current = controller
Original file line number Diff line number Diff line change @@ -193,20 +193,20 @@ export const AutocompleteDropdown = memo<
193
193
useEffect ( ( ) => {
194
194
const initialDataSet = initialDataSetRef . current
195
195
const initialValue = initialValueRef . current
196
- if ( ! Array . isArray ( initialDataSet ) ) {
197
- // nothing to set or already setted
198
- return
199
- }
200
196
201
- let dataSetItem : AutocompleteDropdownItem | undefined
197
+ let initialValueItem : AutocompleteDropdownItem | undefined
202
198
if ( typeof initialValue === 'string' ) {
203
- dataSetItem = initialDataSet . find ( el => el . id === initialValue )
199
+ initialValueItem = initialDataSet ? .find ( el => el . id === initialValue )
204
200
} else if ( typeof initialValue === 'object' && initialValue . id ) {
205
- dataSetItem = initialDataSet . find ( el => el . id === initialValue ?. id )
201
+ initialValueItem = initialDataSet ?. find ( el => el . id === initialValue ?. id )
202
+ if ( ! initialValueItem ) {
203
+ // set the item as it is if it's not in the list
204
+ initialValueItem = initialValue
205
+ }
206
206
}
207
207
208
- if ( dataSetItem ) {
209
- setSelectedItem ( dataSetItem )
208
+ if ( initialValueItem ) {
209
+ setSelectedItem ( initialValueItem )
210
210
}
211
211
} , [ ] )
212
212
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ export interface IAutocompleteDropdownProps {
28
28
dataSet : AutocompleteDropdownItem [ ] | null
29
29
inputHeight ?: number
30
30
suggestionsListMaxHeight ?: number
31
- initialValue ?: string | { id : string }
31
+ initialValue ?: string | { id : string } | AutocompleteDropdownItem
32
32
loading ?: boolean
33
33
useFilter ?: boolean
34
34
showClear ?: boolean
You can’t perform that action at this time.
0 commit comments