-
Notifications
You must be signed in to change notification settings - Fork 841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EuiOutsideClickDetector fires early on overrides value in firefox #1881
Comments
This problem caused elastic/kibana#35199 - in this case it was possible to work around the issue. |
Looks like in Chrome it's the mousedown event on the select box that bubbles to This means that the exact same interaction with a select in this scenario will result in a different count number depending on the browser 😕 (e.g., single selection results in 1 in both; open and close without selection results in 1 in Chrome and 0 in Firefox) |
It is possible to prevent this specific event from bubbling up (could be implemented in onMouseUp={e => {
if (e.target.nodeName === "OPTION") {
e.nativeEvent.stopImmediatePropagation();
}
}} |
The issue is actually a bit different than my initial observation. FireFox never fires a I think you're right that trying to normalize via |
It's not nice, but probably the best we can do here. The underlying problem is that the reaction of |
Also a good idea. Thanks for putting together the codesandbox repros 👍 |
More news: Safari never fires a |
And to complete the cycle: IE11 fires a |
@chandlerprall I don't see a good way to normalize The originating problem of state update cancellation can be solved by the suggested I could see |
I'm hesitant to make any wide spread and/or sweeping changes here, as everything is functioning as expected-ish (to be honest I'm surprised this doesn't happen in other browsers), and is an unfortunate intersection of React development being component-focused, DOM events retaining their ordering, and browser differences. The provided code sandbox can rectify itself by including a This also appears to be very isolated to native select boxes, where React polyfills the |
All good points. Let me look into browser outcomes for |
I’m also not 100% sure whether React guarantees that onChange will be called synchronously or whether this is just an implementation detail with all that fiber stuff going on - stopping propagation in the first place seems more stable |
In firefox if
EuiOutsideClickDetector
is used in the same React component with a select element and the state is updated by theonOutsideClick
handler, the value of the select element is reset before theonChange
handler of the select is fired which makes it impossible to capture a select change which was triggered by mouse click:https://codesandbox.io/s/m7916933m8
This happens because in firefox a mouseup on an option in a select menu bubbles into the
EuiOutsideClickDetector
which isn't the case in chrome.I'm not sure whether this even counts as React bug. It is possible to work around this by delaying the state update from
onOutsideClick
, but there has to be a better solution to that.The text was updated successfully, but these errors were encountered: