I am using searchable drop-down using the below module.
https://www.npmjs.com/package/react-native-searchable-dropdown
When the drop-down is open, when I click on back button the drop-down does not close. And until I select any option it will be opened only. How to resolve this?
<View style={{ marginTop: 5 }}>
<SearchableDropdown
onItemSelect={(item, index) => {
setItemname(item.value);
setItemIndex(index);
}}
itemStyle={{
padding: 10,
marginTop: 2,
backgroundColor: '#ddd',
borderColor: '#bbb',
borderWidth: 1,
borderRadius: 5,
}}
itemTextStyle={{ color: '#222' }}
itemsContainerStyle={{ maxHeight: 140 }}
items={items}
defaultIndex={itemindex}
resetValue={false}
textInputProps={
{
placeholder: "Select Item",
underlineColorAndroid: "transparent",
style: {
padding: 12,
borderWidth: 1,
borderColor: '#ccc',
borderRadius: 5,
},
}
}
listProps={{
nestedScrollEnabled: true,
}}
/>
</View>
What is happening
The
SearchableDropDowncomponent usesTextInput'sonBlurprop to set itsfocusstate tofalseon blur (code reference).When the
focusstate istruetheFlatListis rendered that contains the items (code reference).The problem is that when you press the back button
onBluris not triggered, meaning thefocusstate is not set tofalseand theFlatListwith the items is still rendered.Possible workaround
You could conditionally hide the flatlist based on whether the keyboard is hidden or not.
The implementation above sets
itemsContainerStyleto an object withdisplayset to'none'when theisKeyboardVisiblestate isfalse.Source used for hiding/showing keyboard