我有一个组件,当您单击它的任何位置时,它会执行一个操作,除非您单击某些具有自己的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>