[GH-ISSUE #3069] [Issue]: Game-assets toolbar New/Columns dropdowns open at the button's left edge with no viewport clamp, so they run off the right screen edge on narrow phones #1637

Closed
opened 2026-10-21 05:41:10 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3069

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

In the Game Assets toolbar, the "New" file dropdown and the "Columns" dropdown (list view) are portaled to document.body and positioned with a fixed left equal to the button's left edge, plus a minimum width of 10rem (160px), with no horizontal clamping against the viewport. On a phone the toolbar action buttons sit in a flex-wrap row and can land near the right edge of the screen. When that happens, the menu extends 160px+ to the right of the button and runs off the right side of the viewport, clipping menu items (e.g. "New markdown file") under the screen edge and/or forcing horizontal overflow. Other comparable portaled menus in the app already clamp themselves into the viewport, so this one is inconsistent. This is mobile-only because on desktop the buttons are never close enough to the right edge for the clamp to matter.

How to reproduce (try it yourself)

  1. On a phone-width viewport (most apparent at <=479px, where the actions row wraps and the New/Columns buttons land near the right edge), open the Game Assets browser (game-mode chat) so the Toolbar is visible.
  2. Switch to List view so the "Columns" button also appears.
  3. Tap "New" (or "Columns") when it is positioned toward the right side of the wrapped actions row.

You'll see: the dropdown opens flush against the button's left edge and its right side is cut off by the screen edge, hiding or clipping the menu options (e.g. "New markdown file").
Expected: the dropdown shifts left as needed to stay fully inside the viewport, the way the source menu and folder-selection menu already do.

Where it is

packages/client/src/components/game-assets/Toolbar.tsx:125-128 sets the New menu position to the raw button left with no clamp:

const openNew = () => {
  const rect = newBtnRef.current?.getBoundingClientRect();
  if (rect) setNewPos({ x: rect.left, y: rect.bottom + 4 });
  setNewOpen((prev) => !prev);
};

Toolbar.tsx:131-134 (openCols) is the identical pattern for the Columns menu. Both are rendered by the dropdown helper at Toolbar.tsx:144-153, which portals to document.body:

className="fixed z-[60] min-w-[10rem] rounded-lg border ... shadow-xl"
style={{ left: pos.x, top: pos.y }}

So the menu is fixed-positioned, at least 160px wide, anchored at the raw button left, with nothing pulling it back into the viewport.

Siblings that do it right (same codebase): GameAssetsBrowserView.tsx:179 clamps x: Math.max(8, Math.min(rect.left, window.innerWidth - 288)), and BotBrowserView.tsx:1410-1413 clamps left = Math.min(Math.max(SOURCE_MENU_MARGIN, rect.left), Math.max(SOURCE_MENU_MARGIN, window.innerWidth - width - SOURCE_MENU_MARGIN)). The Toolbar dropdowns lack any equivalent.

What's happening

left is set to the raw rect.left of the button with no Math.min against window.innerWidth - menuWidth - margin. When a button sits near the right edge of a narrow viewport, the menu's right edge (left + >=160px) exceeds window.innerWidth, so the overflowing portion is clipped under the right screen edge. Because the position is an inline style.left, no CSS media query can rescue it — there's no custom class hook on the portaled element (it carries only Tailwind utilities), and the inline style would override CSS left anyway. The buttons genuinely render on mobile: the Columns button appears whenever viewMode === "list", and the New button always renders (only its text span is max-sm:hidden, so the icon button still shows in the flex flex-wrap actions row). The toolbar's container is full-width on phones (.app-right-panel-mobile is width: 100% !important in globals.css), so there is no surrounding max-width to keep the button off the edge.

Suggested fix

Clamp x in both openNew and openCols against the viewport, matching the sibling menus. Add module-level constants const TOOLBAR_MENU_WIDTH = 176; (11rem — covers the min-w-[10rem]=160px menu plus the widest item "New markdown file" with its icon and px-3 padding) and const TOOLBAR_MENU_MARGIN = 8;, then:

const openNew = () => {
  const rect = newBtnRef.current?.getBoundingClientRect();
  if (rect) setNewPos({
    x: Math.max(TOOLBAR_MENU_MARGIN, Math.min(rect.left, window.innerWidth - TOOLBAR_MENU_WIDTH - TOOLBAR_MENU_MARGIN)),
    y: rect.bottom + 4,
  });
  setNewOpen((prev) => !prev);
};

const openCols = () => {
  const rect = colsBtnRef.current?.getBoundingClientRect();
  if (rect) setColsPos({
    x: Math.max(TOOLBAR_MENU_MARGIN, Math.min(rect.left, window.innerWidth - TOOLBAR_MENU_WIDTH - TOOLBAR_MENU_MARGIN)),
    y: rect.bottom + 4,
  });
  setColsOpen((prev) => !prev);
};

Using a concrete width constant (rather than an unmeasured placeholder) keeps this consistent with GameAssetsBrowserView.tsx:179, which also hardcodes its menu width. An optional maxHeight clamp against window.innerHeight can be added but is not load-bearing for this horizontal-overflow bug.

Regression avoided: this is a pure JS clamp on the inline left value computed from window.innerWidth. It touches no Tailwind classes (no max-md:/max-sm: leak), no z-index, no hover/visibility state, and does not reflow the flex actions row, so desktop and all other breakpoints are unaffected. On wide/desktop viewports rect.left is far below window.innerWidth - TOOLBAR_MENU_WIDTH - TOOLBAR_MENU_MARGIN, so Math.min returns rect.left unchanged — identical to current behavior. Only positional math changes, so light/dark/sillytavern themes are untouched. It mirrors the already-shipped clamps in the same files, making the codebase more consistent, not less.

AI-investigated against v2.0.6 (packages/client); cited lines read and confirmed. Mobile layout verified by reading the computed Tailwind classes + globals.css, not on a device — please confirm on a phone before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3069 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** In the Game Assets toolbar, the "New" file dropdown and the "Columns" dropdown (list view) are portaled to `document.body` and positioned with a fixed `left` equal to the button's left edge, plus a minimum width of 10rem (160px), with no horizontal clamping against the viewport. On a phone the toolbar action buttons sit in a `flex-wrap` row and can land near the right edge of the screen. When that happens, the menu extends 160px+ to the right of the button and runs off the right side of the viewport, clipping menu items (e.g. "New markdown file") under the screen edge and/or forcing horizontal overflow. Other comparable portaled menus in the app already clamp themselves into the viewport, so this one is inconsistent. This is mobile-only because on desktop the buttons are never close enough to the right edge for the clamp to matter. **How to reproduce (try it yourself)** 1. On a phone-width viewport (most apparent at <=479px, where the actions row wraps and the New/Columns buttons land near the right edge), open the Game Assets browser (game-mode chat) so the Toolbar is visible. 2. Switch to List view so the "Columns" button also appears. 3. Tap "New" (or "Columns") when it is positioned toward the right side of the wrapped actions row. You'll see: the dropdown opens flush against the button's left edge and its right side is cut off by the screen edge, hiding or clipping the menu options (e.g. "New markdown file"). Expected: the dropdown shifts left as needed to stay fully inside the viewport, the way the source menu and folder-selection menu already do. **Where it is** `packages/client/src/components/game-assets/Toolbar.tsx:125-128` sets the New menu position to the raw button left with no clamp: ```tsx const openNew = () => { const rect = newBtnRef.current?.getBoundingClientRect(); if (rect) setNewPos({ x: rect.left, y: rect.bottom + 4 }); setNewOpen((prev) => !prev); }; ``` `Toolbar.tsx:131-134` (`openCols`) is the identical pattern for the Columns menu. Both are rendered by the `dropdown` helper at `Toolbar.tsx:144-153`, which portals to `document.body`: ```tsx className="fixed z-[60] min-w-[10rem] rounded-lg border ... shadow-xl" style={{ left: pos.x, top: pos.y }} ``` So the menu is fixed-positioned, at least 160px wide, anchored at the raw button left, with nothing pulling it back into the viewport. Siblings that do it right (same codebase): `GameAssetsBrowserView.tsx:179` clamps `x: Math.max(8, Math.min(rect.left, window.innerWidth - 288))`, and `BotBrowserView.tsx:1410-1413` clamps `left = Math.min(Math.max(SOURCE_MENU_MARGIN, rect.left), Math.max(SOURCE_MENU_MARGIN, window.innerWidth - width - SOURCE_MENU_MARGIN))`. The Toolbar dropdowns lack any equivalent. **What's happening** `left` is set to the raw `rect.left` of the button with no `Math.min` against `window.innerWidth - menuWidth - margin`. When a button sits near the right edge of a narrow viewport, the menu's right edge (`left + >=160px`) exceeds `window.innerWidth`, so the overflowing portion is clipped under the right screen edge. Because the position is an inline `style.left`, no CSS media query can rescue it — there's no custom class hook on the portaled element (it carries only Tailwind utilities), and the inline style would override CSS `left` anyway. The buttons genuinely render on mobile: the Columns button appears whenever `viewMode === "list"`, and the New button always renders (only its text span is `max-sm:hidden`, so the icon button still shows in the `flex flex-wrap` actions row). The toolbar's container is full-width on phones (`.app-right-panel-mobile` is `width: 100% !important` in globals.css), so there is no surrounding max-width to keep the button off the edge. **Suggested fix** Clamp `x` in both `openNew` and `openCols` against the viewport, matching the sibling menus. Add module-level constants `const TOOLBAR_MENU_WIDTH = 176;` (11rem — covers the `min-w-[10rem]`=160px menu plus the widest item "New markdown file" with its icon and `px-3` padding) and `const TOOLBAR_MENU_MARGIN = 8;`, then: ```tsx const openNew = () => { const rect = newBtnRef.current?.getBoundingClientRect(); if (rect) setNewPos({ x: Math.max(TOOLBAR_MENU_MARGIN, Math.min(rect.left, window.innerWidth - TOOLBAR_MENU_WIDTH - TOOLBAR_MENU_MARGIN)), y: rect.bottom + 4, }); setNewOpen((prev) => !prev); }; const openCols = () => { const rect = colsBtnRef.current?.getBoundingClientRect(); if (rect) setColsPos({ x: Math.max(TOOLBAR_MENU_MARGIN, Math.min(rect.left, window.innerWidth - TOOLBAR_MENU_WIDTH - TOOLBAR_MENU_MARGIN)), y: rect.bottom + 4, }); setColsOpen((prev) => !prev); }; ``` Using a concrete width constant (rather than an unmeasured placeholder) keeps this consistent with `GameAssetsBrowserView.tsx:179`, which also hardcodes its menu width. An optional `maxHeight` clamp against `window.innerHeight` can be added but is not load-bearing for this horizontal-overflow bug. Regression avoided: this is a pure JS clamp on the inline `left` value computed from `window.innerWidth`. It touches no Tailwind classes (no `max-md:`/`max-sm:` leak), no z-index, no hover/visibility state, and does not reflow the flex actions row, so desktop and all other breakpoints are unaffected. On wide/desktop viewports `rect.left` is far below `window.innerWidth - TOOLBAR_MENU_WIDTH - TOOLBAR_MENU_MARGIN`, so `Math.min` returns `rect.left` unchanged — identical to current behavior. Only positional math changes, so light/dark/sillytavern themes are untouched. It mirrors the already-shipped clamps in the same files, making the codebase more consistent, not less. *AI-investigated against v2.0.6 (packages/client); cited lines read and confirmed. Mobile layout verified by reading the computed Tailwind classes + globals.css, not on a device — please confirm on a phone before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Addressed in PR #3072 by commit 4146a380. Validated locally with pnpm check and pnpm smoke:ui.

<!-- gh-comment-id:4836258356 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Addressed in PR #3072 by commit 4146a380. Validated locally with pnpm check and pnpm smoke:ui.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1637
No description provided.