javascript - react-select: stopPropagation when clicking on an option
问题描述
I have a react-select wrapped in a parent component. The parent has its own onClick
which shouldn't fire when an option from the dropdown menu is clicked. However it should fire when the dropdown control is clicked and the menu expanded.
Due to how react-select is designed, the onChange
prop doesn't actually pass the event, as there is a lack of reliable events for onChange
.
I tried wrapping the select in another component with onClick={(e)=>e.stopPropagation}
, but that stops the parent onClick
from firing all together, while I only want to stop propagating when an option is clicked.
I guess another way of asking this question would be how to differentiate dropdown control click and menu option click in react-select. (and still, how to get the underlying event to be able to call event.stopPropagation
)
Here's a similar question but the accepted answer didn't work for me.
解决方案
推荐阅读
- android - 错误:命令失败:./gradlew app:installDebug -PreactNativeDevServerPort=8081
- smartcontracts - 为什么像 signer_account_id 这样的环境变量会导致错误:ProhibitedInView?
- jquery - jQuery 日期选择器。我如何从 Jquery datepicker 中获取年份
- r - 在 R 中使用 get() 的问题 - 找不到对象(可能与环境有关?)
- .net - 如何在 Powershell 中删除表头并转换为日期类型?
- godot - 使用 InputEventScreenTouch 缩放时的 TileMap 坐标错误
- .net-core - NetCore 使用 SecurityToken 连接到 WCF
- junit - 冲突 org.springframework.boot.test.context.SpringBootTest; 和 org.springframework.test.context.junit.jupiter.SpringExtension;
- storage - 我应该如何篡改证明文件,以便只有我的应用程序可以修改它而不是用户
- powerbi - 来自测量的 PowerBI ZSCORE