-
Notifications
You must be signed in to change notification settings - Fork 238
fix(context-menu): position anchor and prevent escaping container COMPASS-9673 #7192
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
Conversation
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.
Pull Request Overview
This PR fixes a positioning issue in the context menu component when it's embedded within containers that have position: relative
. The fix changes the anchor positioning from absolute
to fixed
to ensure the context menu is positioned relative to the viewport rather than the containing element.
- Changes context menu anchor positioning from
absolute
tofixed
I think we discussed this on the standup, do you mind commiting this code also so that we have an environment that's a bit closer to mms? |
1bc2235
to
c436d82
Compare
} | ||
#container { | ||
--offset: 30px; | ||
position: absolute; |
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.
Using position absolute and having an offset in every direction ensures any position: relative;
contained will resolve its position relative to this with the offset, triggering the original issue.
useEffect(() => { | ||
// Don't set up event listeners if we have a parent context | ||
if (parentContext || disabled) return; | ||
// We skip registering listeners when parentContext is known to avoid registering multiple (nested) listeners |
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.
Drive-by to have the comment say something about, why we're actually doing this.
ref={anchorRef} | ||
style={{ | ||
position: 'absolute', | ||
position: 'fixed', |
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.
The actual fix for the original bug.
ContextMenuItemGroup, | ||
} from '@mongodb-js/compass-context-menu'; | ||
|
||
const containerStyles = css({ |
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.
This container is not just a part of the provider from the compass-context-menu
package, because we need access to the css
helper, which would introduce a circular dependency.
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.
This probably should be display: contents
so that it doesn't create its own box and allows parent and children to keep their styles without the need to account for this extra element (we do something pretty similar here).
Also if this belongs to the context-menu rather than to compass-components, it should probably stay there, you can inline styles with a style property to avoid the dependency, although ContextMenuProviderBase
being configurable like that also looks good to me. I would rather pass the ref directly maybe, this seems to be a more common pattern that I see in these cases, but no strong preference for that, local state keeping the value around is also okay.
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.
This probably should be
display: contents
Great idea - thanks for pointing to that.
if this belongs to the context-menu rather than to compass-components, it should probably stay there
This was mostly to avoid inline styling, so I agree this could live in the context menu package, when it's just a display: contents
.
d886c3a
to
332bfe0
Compare
For some reason, this test is failing: compass/packages/compass-components/src/components/workspace-tabs/tab.spec.tsx Lines 94 to 98 in 8f183d0
It doesn't fail when I run it in isolation (using Also tried changing this to (without luck - still failing when all tests are ran):
|
Skipping the failing test for now and created COMPASS-9730 to track un-skipping it again. |
71a8479
to
c531e7f
Compare
Seems like this somehow actually breaks e2e tests on web? Maybe just very unlucky flakes EDIT: nope, consistently fails |
Reverting changes to the sandbox html page seems to fix the failing test in chrome (and this seems to only affect ci, I can't repro this running these tests locally or running this code in mms), very surprising, but to unblock this, I think I'll just revert the changes to index.html for now |
8f16187
to
5af30b5
Compare
For whatever reason they are breaking one particular test in web in chrome in CI
5af30b5
to
6f82bf1
Compare
Description
When embedded as the data-explorer, the right click menu is rendered inside a container with
position: relative;
.When the context menu anchor is positioned absolute, it will be relative to that container.
Merging this PR will:
display: contents
wrapping thechildren
of theContextMenuProvider
, to which the "root" "contextmenu" listener gets added.I tested this locally by modifying the
compass-web
sandbox to reproduce the bug and update the code to fix it.I pushes a commit with the change I did to the sandbox and verified using the "compass-web" sandbox as well as "compass".
Checklist
Motivation and Context
Open Questions
Dependents
Types of changes