hoaphantn7604 / react-native-element-dropdown

A react-native dropdown component easy to customize for both iOS and Android.
MIT License
1.02k stars 173 forks source link

Disable a menu item #291

Open jobberma opened 3 months ago

jobberma commented 3 months ago

Hello,

The plugin is great. I need to make a parent category menu item disabled.

Is there a way to do that ?

Thanks

DanBizu commented 2 weeks ago

I also needed this, seems like the library has some default behavior for the dropdown items and there is no way to overwrite it. Yet I was able to achieve something in a counterintuitive way, by wrapping the items in a Pressable, like so:

renderItem={(item) => (<Pressable
     disabled={item.isEnabled}
     style={[
        styles.dropdownItemStyle,
        !item.isEnabled && styles.dropdownItemDisabled,
     ]}
  >
     <Text>{item.text}</Text>
  </Pressable>)

Not sure I fully understand why it works, as you can notice, the disable/enable logic is reversed, my theory is that the Pressable captures all the press events, this way preventing the default behavior of the item press.