I just debug principle plugin’s context menu wrong position problem, so share it here.
Saq’s streams plugin popup a context menu in this way (this is how you can create your own context menu, or popup window under mouse click):
-
$eventcatcher
widget listens on event of element, like.stream-row
. It can listen on many events, including swiped-right and right click -
$eventcatcher
provides position of the mouse or finger by prividing variable<<tv-popup-abs-coords>>
to all its children, and callbacks on it - A callback like
actions-swiped-right=<<swiped-right-actions>>
on it, might contains a$action-popup
-
$action-popup
will use<<tv-popup-abs-coords>>
or<<tv-popup-coords>>
to compute the coordinates of popup element to show, the coordinates are putted into a state tiddler you provided, for example$:/state/sq-context-popup
- You can use
$reveal
widget’s popup mode, following position in$:/state/sq-context-popup
tiddler, to position the context menu relative to<body>
.
Why the position is relative to <body>
? Accroding to TW core’s source code, it is acturally relative to offsetParent of the popup element, it is usually the document.body
.
And if the parent container has If the parent container has scrolling, you will find that no matter how you scroll, the menu is in a fixed position relative to the page, and then the positioning will be wrong relative to the scrolled content.
So if the popup’s position is wrong:
- Try to remove scrolling from one of the upper containers.
- e.g. remove the
height: 100vh;
restriction or remove theoverflow-y: auto;
attribute - Or make container a offsetParent of the context menu, e.g. by adding
position: absolute;top: 0;left: 0;
- e.g. remove the