From aae5214cde680faf81d22f179730d2efd57be7a0 Mon Sep 17 00:00:00 2001 From: Krao Hasanee Date: Tue, 2 Jun 2026 15:15:54 -0400 Subject: [PATCH] fix: context menu via createPortal, renders at viewport coords --- src/components/FileBrowser.jsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/FileBrowser.jsx b/src/components/FileBrowser.jsx index 7469e08..9fee7e1 100644 --- a/src/components/FileBrowser.jsx +++ b/src/components/FileBrowser.jsx @@ -1,4 +1,5 @@ import { useEffect, useMemo, useRef, useState } from 'react'; +import { createPortal } from 'react-dom'; import LoadingButton from './LoadingButton'; import SortTh from './SortTh'; import { supabase } from '../lib/supabase'; @@ -310,10 +311,7 @@ export default function FileBrowser({ initialPath = '/', rootPath = '/' }) { const openCtxMenu = (e, entry, childPath) => { e.preventDefault(); e.stopPropagation(); - const menuW = 180, menuH = 320; - const x = e.clientX + menuW > window.innerWidth ? window.innerWidth - menuW - 8 : e.clientX; - const y = e.clientY + menuH > window.innerHeight ? e.clientY - menuH : e.clientY; - setCtxMenu({ x: Math.max(4, x), y: Math.max(4, y), entry, childPath }); + setCtxMenu({ x: e.clientX, y: e.clientY, entry, childPath }); }; return ( @@ -445,9 +443,9 @@ export default function FileBrowser({ initialPath = '/', rootPath = '/' }) { )} - {/* Context menu */} - {ctxMenu && ( -
e.stopPropagation()} style={{ ...popupMenuStyle, position: 'fixed', left: ctxMenu.x, top: ctxMenu.y, zIndex: 1000, padding: '4px 0', minWidth: 160 }}> + {/* Context menu — portal to escape stacking context */} + {ctxMenu && createPortal( +
e.stopPropagation()} style={{ ...popupMenuStyle, position: 'fixed', left: ctxMenu.x, top: ctxMenu.y, zIndex: 9999, padding: '4px 0', minWidth: 160 }}> {ctxMenu.entry?.type === 'dir' && ( )} -
+
, + document.body )} );