-
Notifications
You must be signed in to change notification settings - Fork 29
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
The menu always opens to the bottom from the anchor element and overlaps container. #788
Comments
Hey @Kost927! 👋 I'm here to help you with bug fixes, answer questions, and assist you in becoming a contributor. To address the issue of the menu overlapping the screen at the bottom, you can modify the useEffect(() => {
if (!anchor) {
return;
}
if (!render) {
if (anchorChild) {
anchorChild.remove();
setAnchorChild(null);
}
return;
}
const { height, bottom } = anchor.getBoundingClientRect();
const newAnchorChild = anchorChild ?? document.createElement("div");
newAnchorChild.style.position = "absolute";
newAnchorChild.style.left = "0";
newAnchorChild.style.right = "0";
newAnchorChild.style.paddingTop = `${height}px`;
// Adjust the position if the menu would overflow the screen
if (bottom + height > window.innerHeight) {
newAnchorChild.style.bottom = "0";
newAnchorChild.style.top = "auto";
} else {
newAnchorChild.style.top = "0";
newAnchorChild.style.bottom = "auto";
}
anchor.prepend(newAnchorChild);
if (!anchorChild) {
setAnchorChild(newAnchorChild);
}
const anchorObserver = new ResizeObserver(([entry]) => {
newAnchorChild.style.paddingTop = `${entry.contentRect.height}px`;
});
anchorObserver.observe(anchor);
setTimeout(() => {
newAnchorChild.className = comboboxAnchorClassName ?? "";
});
return () => {
anchorObserver.disconnect();
anchor.removeChild(newAnchorChild);
};
}, [anchor, render, anchorChild, comboboxAnchorClassName]); This code checks if the menu would overflow the screen at the bottom and adjusts its position accordingly, ensuring it stays within the viewport [1]. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
wrote a huck, if someone will need it in a feature.
I have fullscreen mode, so I need to add a new portal to move the menu inside the fullscreen container, if not, createPortal and logic with bottom placement is not needed as the menu is in the bottom by default.
Can add an intersection observer if needed, but in my case, the placement "top" and "bottom" is enough. |
Describe the bug
The menu always opens to the bottom from the anchor element.
To Reproduce
Steps to reproduce the behavior:
add rich editor on the bottom of the screen
open mention menu
Expected behavior
The menu doesn't overlap with the screen at the bottom.
Screenshots
https://github.com/user-attachments/assets/10ad8a64-eba3-4f4c-a75a-78ca8d723ac6
Desktop (please complete the following information):
any device, any browser
Additional context
We would like to choose menu placement, or automatically place it if the menu overlaps the container.
The text was updated successfully, but these errors were encountered: