Chr*_* W. 1 javascript ecmascript-6 reactjs react-select
我有一个组件,当你点击它的任何地方时它会执行一个动作,除非你点击某些有自己onClick
处理程序的子组件。这些onClick
处理程序能够通过调用e.stopPropagation
. 我如何类似地捕获和stopPropagation()
在ReactSelect
组件的onClick
事件上?普通onClick
处理程序永远不会被调用。
这基本上是所描述的设置(ES6):
handleMost = e => {
// Note that I cannot check e.target here, because there is a bunch
// of other stuff that might be the target that still should cause
// the standard action to occur
doStandardThing();
}
handleFoo = e => { e.stopPropagation(); doSomethingFoo(); }}
handleBar = e => { e.stopPropagation(); doSomethingBar(); }}
handleBaz = e => { e.stopPropagation(); doSomethingBaz(); }}
<ListItem onClick={handleMost}>
<Foo onClick={handleFoo}
<Bar onClick={handleBar}
<ReactSelect ?????={handleBaz}
<OtherStuff ...>
</ListItem>
Run Code Online (Sandbox Code Playgroud)
我查看了 react-select 中的所有事件,但似乎不符合您的目的。
我想作为一种解决方法,您可以尝试将ReactSelect
组件包装在另一个元素中。
<span onClick={e => ....}>
<ReactSelect />
</span>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1193 次 |
最近记录: |