Issue 395 Ticket Flyouts Ran Off The Bottom - edmozley/freeitsm GitHub Wiki

🖱️ #395 Ticket right-click flyouts ran off the bottom of the window

GitHub #395, reported and fixed by @cloudcogsio · Tickets · fixed in 5.7.0 (#3004)

What you saw

In Tickets, right-click a ticket low in the list and hover a flyout - Set type, Assign to, Move to company. The flyout opened downward from its row and ran past the bottom of the window: the entries below the edge could not be seen or clicked, and the bottom of its own scrollbar was off the page too, so scrolling inside it did not reach them.

What was wrong

A flyout (.ticket-context-submenu, assets/css/inbox.css) sits beside its row at top: -5px with max-height: 320px, so it always runs downward. openTicketContextMenu() kept the menu inside the window and flipped flyouts left near the right edge, but nothing did the same at the bottom. And because a tall menu is moved up to fit, its lower rows - Assign to, Move to company - end up near the bottom whichever ticket was right-clicked.

The fix

@cloudcogsio sent the fix on a branch; it is merged with his authorship. fitTicketContextSubmenu() (assets/js/inbox.js) runs each time a flyout opens, by hover or keyboard focus:

sub.style.maxHeight = Math.min(cssMax, window.innerHeight - 2 * MARGIN) + 'px';   // never taller than the window
const over = r.bottom - (window.innerHeight - MARGIN);
if (over > 0) sub.style.top = (Math.max(MARGIN, r.top - over) - parent.getBoundingClientRect().top) + 'px';   // slide up until it fits

It measures every time because the menu's position and the flyout's length change from one right-click to the next. The phone's bottom sheet is untouched.

📁 Files

File Change
🟡 assets/js/inbox.js fitTicketContextSubmenu() and its hover / focus listeners
⚪ tickets/index.php inbox.js?v=214

How it was verified

Reproduced first on a test install, right-clicking the lowest ticket in a 520px-tall window, old code: Set type ran 135px past the bottom, Assign to 199px, Assign to team 15px. With the fix, every flyout ended inside the window at 320, 520 and 700px; at 320px Assign to (10 entries) was capped at the window's height and scrolled.

What this means for you

Update to 5.7.0 and hard-refresh (Ctrl-F5). Every entry in every flyout can be reached, wherever you right-click.

Follow-up in 5.8.0: the menu itself was taller than the window

Ed tested 5.7.0 on his own install and the flyouts were fixed - but Move to trash, the menu's last item, was below the bottom of the screen. With every module switched on the menu has more than twenty entries, and the menu itself (not a flyout) was taller than the window, so no amount of sliding up could fit it.

openTicketContextMenu() now works in three steps, measured each time it opens:

  1. It fits - placed at the pointer as before, nudged up if it would run off.
  2. It does not fit - the rows tighten (ctx-compact: 5px instead of 8px above and below each). On a normal laptop screen that is enough.
  3. It still does not fit - it is capped at the window and scrolls (ctx-scroll), with no visible scrollbar.
const roomY = window.innerHeight - 2 * MENU_MARGIN;
if (menu.getBoundingClientRect().height > roomY) menu.classList.add('ctx-compact');
if (menu.getBoundingClientRect().height > roomY) { menu.classList.add('ctx-scroll'); menu.style.maxHeight = roomY + 'px'; }

TRAP: a scrolling box clips everything outside it - including the flyouts beside it. So in ctx-scroll mode fitTicketContextSubmenu() places each flyout with position: fixed against the window, beside its row and overlapping the menu's edge by 2px; and a scroll of the menu re-places an open flyout. The scrollbar is hidden because a scrollbar between a row and its flyout is a gap the pointer falls through on its way in, closing the flyout - the wheel and the trackpad still scroll. Desktop only (reading-pane.css, v=8); the phone shows the menu as a sheet.

Checked headless on the test install at 1000, 560 and 420 pixels high: the menu fits as it was, then compact, then compact and scrolling; Move to trash is on screen in each; the last flyout opens beside the menu with no gap and fits the window in all three (fixed in the scrolling case).

Related: Tickets · Inbox JS - Developer Guide