-
-
Notifications
You must be signed in to change notification settings - Fork 317
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
Add ContextMenu component #1213
Conversation
Make sure that multiple context menus can't be open at the same time.
Codecov Report
@@ Coverage Diff @@
## master #1213 +/- ##
=======================================
Coverage 93.39% 93.39%
=======================================
Files 113 113
Lines 4332 4332
=======================================
Hits 4046 4046
Misses 286 286
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
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.
@seancolsen Nice work! The component looks good to me.
I have a couple comments:
- Older versions of Safari do not support pointer events as you've mentioned on the PR description (Safari is the new Internet Explorer.. sigh). These older versions are only 2 years old (2019) and are still in considerable use. I'd suggest writing a mini polyfill, where we check if
pointerdown
is present and use it, and if not, we usemousedown
(which is also supported by all touch devices, although certain devices may behave inconsistently). - The styles in
ContextMenu
component should be marked global.
It's not needed because we're already using `dropdown` and `content` classes.
@pavish ready for re-review
Done in c7c83a2. I chose to also add a listener for the
Addressed in 449a244 by removing that CSS since it was actually redundant. I meant to take that out earlier. Thanks for catching that. |
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.
@seancolsen Looks good to me!
Related to #930
Summary
ContextMenu
component to our component library.Rationale
Notes
clickOffBounds.ts
, I changed the event fromclick
topointerdown
so that the event is triggered for context menu interactions as well. I did this to ensure that only one context menu would be open at a time, but it also changes the behavior of things like Dropdown and Select so that they close when the user right-clicks somewhere else. To me that seems slightly better. Thepointerdown
event is part of the Pointer Events API which has decent support, but not perfect. Some older versions of Safari don't support it. Personally, I think we're probably fine here, but if you have concerns about this approach, I can add multiple event listeners instead.Demo
Usage
Add a context menu to a
div
like thisClicking anywhere within the
div
will open the menu.Checklist
Update index.md
).master
branch of the repositoryDeveloper Certificate of Origin
Developer Certificate of Origin