-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(OverflowMenu): call closeMenu method only when menu is open #5336
fix(OverflowMenu): call closeMenu method only when menu is open #5336
Conversation
Deploy preview for carbon-elements ready! Built with commit bb8930e |
Deploy preview for carbon-components-react ready! Built with commit bb8930e https://deploy-preview-5336--carbon-components-react.netlify.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple fix that greatly improves the performance 🎉 - Thanks @emyarod!
cc @vpicone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @emyarod thanks for tackling this. A big improvement!
🎉 |
Closes #5079
This PR adds an open state check to the
handleClickOutside
method so that the click listener correctly fires only when the menu is open.Prior to this change, the click handler would fire with every click outside of the component regardless of the component state, meaning that for every overflow menu on a page, each click would trigger a
handleClickOutside
function call even if the menus were closed. As shown in the demo provided in the original ticket, this led to the action of opening a single overflow menu taking over 4 seconds on a page containing 500 menu instances.With this check for menu state, the time taken for a single menu to open on the same demo is reduced to 19 milliseconds.
Changelog
Changed
handleClickOutside
methodTesting / Reviewing
To test this locally, you can recreate the demo by adding this as a story in storybook and comparing it to the demo in the original ticket: