我有一個組件,當你點擊它的任何地方時,它會執行一個動作,除非你點擊某個有自己onClick
處理程序的子組件。這些onClick
處理程序可以通過呼叫e.stopPropagation
來阻止其父母執行標準操作。我如何在ReactSelect
組件的onClick
事件上類似地捕獲並stopPropagation()
?正常的onClick
句柄永遠不會被調用。如何用`react-select`組件爲'onClick`事件調用`e.stopPropagation()`?
這基本上是描述(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>
您能否在codepen或webpackbin中設置一個工作示例? –
嘗試'onChange'屬性 – maioman
@maioman的'onChange'屬性返回修改後的值作爲第一個參數,而不是相關的點擊事件 –