A problem with the menu positioning inside scrollable containers #3775
-
Hey guys, We're having a problem with using menu in data grids. In some cases we have to make grid scrollable horizontally when the content doesn't fix the available with (either via the And this is where the current implementation of the Here's a link to Codesandbox illustrating the problem. Usually, a way to work around such issues is to use portals to render the menu in a different DOM container than the trigger (e.g. document body). We tried it on our side by wrapping the |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
🤖 Hey there, @dmitriy-kudelko! Fancy seeing you here again. Hope you've been doing well since our last cosmic rendezvous in the world of code. 🌌 I'm diving into your issue now and will orbit back shortly with some insights. |
Beta Was this translation helpful? Give feedback.
-
Disclaimer: This is a very experimental bot using OpenAI's GPT-4. The answers may not be correct, a human will review the answer and update it if necessary. Sorry, I don't know how to help with that. I did do a search though, and I managed to find these other Discussions that might be similar or related to your question. Give them a read to see if they answer your question. If they do, head back here and update this discussion and mark it as answered, pointing others to the related discussion:
|
Beta Was this translation helpful? Give feedback.
-
🤖 Thank you for bringing this issue to our attention. It seems like you're encountering a common problem when dealing with overflow and positioning in CSS. The issue arises because the menu is a child of the grid container, and when the menu tries to overflow the grid container, the browser adds scrollbars to the container. Using In the current implementation of the Paste design system, the positioning of the menu is handled by the MenuPrimitive component from the "@twilio-paste/menu-primitive" package. The actual positioning logic is not provided in the context, but it's likely that it uses CSS positioning properties (like To solve the positioning issue when using Here's a simplified example of how you might implement this: const triggerRef = useRef(null);
const triggerRect = triggerRef.current.getBoundingClientRect();
const menuStyle = {
position: 'fixed',
top: `${triggerRect.top}px`,
left: `${triggerRect.left}px`,
};
return (
<>
<button ref={triggerRef}>Open menu</button>
{isOpen && ReactDOM.createPortal(
<Menu style={menuStyle}>Menu content</Menu>,
document.body
)}
</>
); Please note that this is a simplified example and might not cover all edge cases. For example, you might need to update the position of the menu when the window is resized or when the user scrolls. I hope this helps! If you have any further questions or need more clarification, please let me know. Sources
|
Beta Was this translation helpful? Give feedback.
-
Hi @dmitriy-kudelko, You can force the Menu dropdown to open in a portal by calling const menu = useMenuState({modal: true}); Let me know if that solves your issue. I plan to add some documentation around this soon. |
Beta Was this translation helpful? Give feedback.
Hi @dmitriy-kudelko,
You can force the Menu dropdown to open in a portal by calling
useMenuState
like this:Let me know if that solves your issue. I plan to add some documentation around this soon.