Skip to content
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

Fix React@17 event delegation #5940

Closed
wants to merge 8 commits into from
Closed

Conversation

patrykkopycinski
Copy link
Contributor

@patrykkopycinski patrykkopycinski commented Jun 1, 2022

Summary

This PR fixes the issue discovered here elastic/kibana#128239 (comment)
In React@17 there were changes made to the Event delegation described here https://reactjs.org/blog/2020/08/10/react-v17-rc.html#changes-to-event-delegation
In Canvas/Lens app we are using stopPropagation() which in React@17 prevents EuiFocusTrap, EuiOutsideClickDetector to receive the events, so that PR aims to fix it by adding { capture: true } to force the event listeners to receive the event despite the stopPropagation()

Checklist

  • Checked in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs and playground toggles
  • Added documentation
  • Checked Code Sandbox works for any docs examples
  • Added or updated jest and cypress tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • Updated the Figma library counterpart
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

7 similar comments
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

@patrykkopycinski patrykkopycinski marked this pull request as ready for review June 2, 2022 16:11
@patrykkopycinski patrykkopycinski self-assigned this Jun 2, 2022
@thompsongl
Copy link
Contributor

Makes sense given the use case, but I'm still trying to work out whether there are further/unintended consequences. Anything coming to mind for you, @chandlerprall?

@chandlerprall
Copy link
Contributor

It wouldn't surprise me if there's an app somewhere that has a stopPropagation that this could break, but the components touched looks like a good set - and it reinforces eui's intention for these events.

I don't think it makes sense to move the resize or scroll events into the capture phase?

@cee-chen
Copy link
Contributor

cee-chen commented Jun 6, 2022

I'm also a little worried about possible unintended changes as a result of this fix. I'm wondering if it makes more sense to make this a prop that sets the { capture: true } options, e.g. <EuiFocusTrap isCapture />? So defaulting to non-capture and only adding a capture option for specific consumers that need that behavior?

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

@cee-chen
Copy link
Contributor

Thanks for the isCapture prop update Patryk, the new changes look great.

Could we potentially scope this PR down further to only affect specific desired components that you need? For example:

  • EuiFocusTrap <-- per your PR description, you need this for Lens, so this makes sense to add
  • EuiOutsideClickDetector - same as above
  • EuiPopover <-- I'm not sure this makes sense to add - we always want capture to be true for scroll events, and not allow false. I'm also concerned about side effects here since EuiPopover is used so widely across our components. Is this something your app needs or could we consider removing this from the PR?
  • EuiSelectable <-- I'm also not sure this makes sense to add. Does your app also need this?
  • EuiOverlayMask <-- we've had issues in the past with click events on our overlay mask that Greg had to fix, and I'm a little worried about this potentially reintroducing bugs. @thompsongl do you mind taking a look/verifying that this is safe to use?
  • EuiWindowEvent <-- I like this addition a lot as a more generic approach! Huge ++

Let me know what you think!

@thompsongl
Copy link
Contributor

thompsongl commented Jun 20, 2022

EuiOverlayMask <-- we've had issues in the past with click events on our overlay mask that Greg had to fix, and I'm a little worried about this potentially reintroducing bugs.

Willing to hear arguments against, but I think that EuiOverlayMask should no longer accept an onClick prop. The intention was to give an easy on-outside-click hook, but this is now inconsistent with our other approaches to outside click behavior, which have largely been standardized.

If it's necessary to unblock your React 17 PR, we can add the isCapture prop or prioritize the breaking change to remove onClick.

The suggestion would then be to use EuiFocusTrap in conjunction with EuiOverlayMask as we do in several components (e.g., EuiFlyout and EuiCodeBlock):

<EuiOverlayMask>
  <EuiFocusTrap onClickOutside={onClick} />
</EuiOverlayMask>

I'll open an issue for ^ reglardless

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

# Conflicts:
#	src/components/suggest/__snapshots__/suggest.test.tsx.snap
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5940/

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @patrykkopycinski!

The change to EuiOverlayMask LGTM

Could we potentially scope this PR down further to only affect specific desired components that you need?

I'd like to see this as well. Do you specifically need the configuration for EuiPopover and EuiSelectable?

@patrykkopycinski
Copy link
Contributor Author

@thompsongl I believe so, if I recall correctly we need that for Lens flyout

@cee-chen
Copy link
Contributor

cee-chen commented Jul 1, 2022

@patrykkopycinski can you be a bit more specific about what in the Lens flyout requires either an EuiPopover or EuiSelectable to have a configurable capture event? Is there a popover or selectable in the flyout that's causing issues? I peeked at the linked Kibana issue and it looks like it's just EuiFocusTrap and EuiOutsideClickDetector mentioned in the comments.

@thompsongl
Copy link
Contributor

Hey @patrykkopycinski I see that elastic/kibana#128239 has already merged. Are these EUI changes still wanted/required?

@cee-chen
Copy link
Contributor

cee-chen commented Jan 9, 2023

Hey @patrykkopycinski - we're closing this PR due to staleness, but if you still need this behavior, please feel free to re-open this PR without changes to EuiPopover or EuiSelectable (historically some of our more fragile components that have caused a lot of downstream issues with unexpected changes).

@cee-chen cee-chen closed this Jan 9, 2023
@cee-chen cee-chen deleted the fix/react-17-events branch July 7, 2023 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EuiOverlayMask] Remove onClick in favor of EuiFocusTrap combo
5 participants