-
-
Notifications
You must be signed in to change notification settings - Fork 121
[context menu] Create new ContextMenu
component
#1665
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
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
4d55392
to
a9acad9
Compare
We haven't discussed the API of it. I'm wondering if an ordinary Menu with a different Trigger wouldn't be enough: <Menu.Root>
<Menu.ContextTrigger />
... |
@michaldudak discoverability-wise, it might be better as a component for Radix parity? The Root needs to know if it should act as a context menu, where a component provider works nicely in the API, since otherwise it would need a prop in conjunction with using
|
Testing on an iPhone SE (iOS 17.7.2), a long press on the trigger area when the context menu is already open will make a large text selection: RPReplay_Final1744034094.mp4I screen-capped Safari only but it repros on Firefox and Chrome as well According to react-aria it requires quite a heavy handed approach to handle this for all browsers: https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/interactions/src/textSelection.ts |
06e668f
to
850dee6
Compare
@mj12albert looks like |
Nice, glad we can avoid that extra Safari handling ~ |
We could add an attribute indicating how the menu was open (touch or right-click). It seems that on mobile menus are often placed above the trigger (so they are not covered by user's hand). A callback variant of |
@@ -49,6 +50,8 @@ const MenuPopup = React.forwardRef(function MenuPopup( | |||
onOpenChangeComplete, | |||
} = useMenuRootContext(); | |||
const { side, align, floatingContext } = useMenuPositionerContext(); | |||
const contextMenuContext = useContextMenuRootContext(); | |||
const hasContextMenuParent = Boolean(contextMenuContext) && !nested; |
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.
In the Menubar PR I implemented a more universal solution to determine the menu's parent and its capabilities: https://github.com/mui/base-ui/pull/1684/files#diff-6da7b84ff007a487d62a9d48ba9fb32ad4b286ef666fd3d0419b14e9ebbe472a.
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.
Context menus don't have any parents though, so I think this should suffice?
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.
I'd like to avoid having all kinds of boolean values like nested
, isInContextMenu
, isInMenubar
, (possibly) isInNavigationMenu
. The approach I took in the Menubar PR lets a menu part know what kind of menu it's in in a standard way and provides a type-safe way to access the parent context (without having to check for its existence)
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.
Alright 👍 I'll wait for Menubar to be merged and then use its logic for Menu
This could also be used instead of |
Signed-off-by: atomiks <cc.glows@gmail.com>
ContextMenu
componentContextMenu
component
From https://x.com/rsms/status/1522583516265029633, the click-drag-release flow doesn't work properly: Screen.Recording.2025-05-01.at.01.07.20.movhttps://www.radix-ui.com/primitives/docs/components/context-menu, https://ariakit.org/examples/menu-context-menu don't support this correctly either. So maybe OK to ignore fore a v0 Great to see this, we will need this for 👍 mui/mui-x#12021 |
commit: |
Is it possible to stack two context menus? For example, can one context menu appear when clicking on a div and another when clicking outside of it? I try to do it directly, but sadly it doesn't work: https://codesandbox.io/p/sandbox/sweet-wave-h4lygt ![]() I have two boxes here. Right-clicking the outer one displays the context menu as expected, but right-clicking the inner one does not show its context menu. |
Signed-off-by: atomiks <cc.glows@gmail.com>
Closes #51
Preview: https://deploy-preview-1665--base-ui.netlify.app/react/components/context-menu