From 58bf55704a61e3ed8f56f17b9b32dc9d1464ddf7 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sat, 3 Jan 2026 15:07:29 -0800 Subject: [PATCH] Preserve sidebar item active color when showing context menu --- src-web/components/core/tree/Tree.tsx | 3 ++- src-web/components/core/tree/TreeItem.tsx | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src-web/components/core/tree/Tree.tsx b/src-web/components/core/tree/Tree.tsx index c62f9eb1..46d7b5fe 100644 --- a/src-web/components/core/tree/Tree.tsx +++ b/src-web/components/core/tree/Tree.tsx @@ -679,7 +679,8 @@ function TreeInner( className={classNames( '[&_.tree-item.selected_.tree-item-inner]:text-text', '[&:focus-within]:[&_.tree-item.selected]:bg-surface-active', - '[&:not(:focus-within)]:[&_.tree-item.selected]:bg-surface-highlight', + '[&:not(:focus-within)]:[&_.tree-item.selected:not([data-context-menu-open])]:bg-surface-highlight', + '[&_.tree-item.selected[data-context-menu-open]]:bg-surface-active', // Round the items, but only if the ends of the selection. // Also account for the drop marker being in between items '[&_.tree-item]:rounded-md', diff --git a/src-web/components/core/tree/TreeItem.tsx b/src-web/components/core/tree/TreeItem.tsx index f33ea039..6cec576c 100644 --- a/src-web/components/core/tree/TreeItem.tsx +++ b/src-web/components/core/tree/TreeItem.tsx @@ -235,6 +235,12 @@ function TreeItem_({ e.preventDefault(); e.stopPropagation(); + + // Set data attribute on the list item to preserve active state + if (listItemRef.current) { + listItemRef.current.setAttribute('data-context-menu-open', 'true'); + } + const items = await getContextMenu(node.item); setShowContextMenu({ items, x: e.clientX ?? 100, y: e.clientY ?? 100 }); }, @@ -242,6 +248,10 @@ function TreeItem_({ ); const handleCloseContextMenu = useCallback(() => { + // Remove data attribute when context menu closes + if (listItemRef.current) { + listItemRef.current.removeAttribute('data-context-menu-open'); + } setShowContextMenu(null); }, []);