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(menu): remove unnecessary outside click handler #9528

Merged
merged 3 commits into from
Aug 26, 2021

Conversation

janhassel
Copy link
Member

@janhassel janhassel commented Aug 24, 2021

With React v17, the OverflowMenuNext (v11) component wasn't opening anymore supposedly due to smarter execution of the hooks which led to canBeClosed being true immediately when opened, thus allowing the ClickListener to fire its onOutsideClick event and closing the menu since the registered click was still on the trigger element.

A somewhat recent update to the Menu component added an onBlur event in order to correctly return focus for keyboard users. After some testing I noticed that it renders the ClickListener unnecessary as it more accurately detects when the menu should close in this context. Removing the ClickListener and shifting the rootRef on the <ul> element promises to reduce complexity and fixes the original issue of the menu not opening (more accurately: closing immediately) on React v17.

Changelog

Changed

  • Moved rootRef to <ul> element

Removed

  • Removed ClickListener wrapper on Menu
  • Removed unused autoclose prop (not a breaking change since it's marked as experimental/unstable)

Testing / Reviewing

  • Ensure both the Context menu as well as the unstable_Menu->OverflowMenu stories still work as expected (open correctly and close on outside click) with React v16
  • Test the same with React v17
  • Try to open the ContextMenu in Safari by using right-click and (more importantly) ctrl+click*. The menu should stay open in both cases until an outside click is registered (or a menu item is pressed).

@netlify
Copy link

netlify bot commented Aug 24, 2021

✔️ Deploy Preview for carbon-react-next ready!

🔨 Explore the source changes: e1027c6

🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-react-next/deploys/6127aa1c2ae9c300086caf51

😎 Browse the preview: https://deploy-preview-9528--carbon-react-next.netlify.app

@netlify
Copy link

netlify bot commented Aug 24, 2021

✔️ Deploy Preview for carbon-elements ready!

🔨 Explore the source changes: e1027c6

🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-elements/deploys/6127aa1c5f65020008633f99

😎 Browse the preview: https://deploy-preview-9528--carbon-elements.netlify.app

@netlify
Copy link

netlify bot commented Aug 24, 2021

✔️ Deploy Preview for carbon-components-react ready!
Built without sensitive environment variables

🔨 Explore the source changes: e1027c6

🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-components-react/deploys/6127aa1c93c8910007b764b2

😎 Browse the preview: https://deploy-preview-9528--carbon-components-react.netlify.app

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Things look good with react@16.x

I did a yarn upgrade-interactive and pulled packages/react react/react-dom deps up to v17.0.2 and re-ran storybook. Things look good there too in both safari and chrome. 👍

One thing I did notice in the overflow menu story -- when it opens there is a brief flash of hover/red on the danger item at the bottom. Here's a video, it might help to download it and play at half speed to see it. It's very fast.

flash.of.red.mov

@janhassel
Copy link
Member Author

@tay1orjones Interesting... 🤔 It might have to do with the absolute positioning of the menu, since it theoretically first spawns at x0, y0 before being placed accordingly. If your cursor is on the bottom half of the trigger in this story it would align with the "Delete app" menu item (when the menu is at x0, y0). If you place your cursor on the top half of the trigger, the "Edit routes and access" also gets a hover style though it's far less noticeable since it's just a slight gray and not red.

I'll look further into this and try to fix it in a different PR when I get the chance! Thanks for noticing! 👍

Copy link
Contributor

@andreancardona andreancardona left a comment

Choose a reason for hiding this comment

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

looks good! :)

@andreancardona andreancardona enabled auto-merge (squash) August 26, 2021 14:51
@andreancardona andreancardona merged commit f42860f into carbon-design-system:main Aug 26, 2021
@janhassel janhassel deleted the menu-react17 branch August 27, 2021 09:17
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.

3 participants