Preserve sidebar item active color when showing context menu

This commit is contained in:
Gregory Schier
2026-01-03 15:07:29 -08:00
parent c75d6b815e
commit 58bf55704a
2 changed files with 12 additions and 1 deletions

View File

@@ -679,7 +679,8 @@ function TreeInner<T extends { id: string }>(
className={classNames( className={classNames(
'[&_.tree-item.selected_.tree-item-inner]:text-text', '[&_.tree-item.selected_.tree-item-inner]:text-text',
'[&:focus-within]:[&_.tree-item.selected]:bg-surface-active', '[&: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. // Round the items, but only if the ends of the selection.
// Also account for the drop marker being in between items // Also account for the drop marker being in between items
'[&_.tree-item]:rounded-md', '[&_.tree-item]:rounded-md',

View File

@@ -235,6 +235,12 @@ function TreeItem_<T extends { id: string }>({
e.preventDefault(); e.preventDefault();
e.stopPropagation(); 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); const items = await getContextMenu(node.item);
setShowContextMenu({ items, x: e.clientX ?? 100, y: e.clientY ?? 100 }); setShowContextMenu({ items, x: e.clientX ?? 100, y: e.clientY ?? 100 });
}, },
@@ -242,6 +248,10 @@ function TreeItem_<T extends { id: string }>({
); );
const handleCloseContextMenu = useCallback(() => { const handleCloseContextMenu = useCallback(() => {
// Remove data attribute when context menu closes
if (listItemRef.current) {
listItemRef.current.removeAttribute('data-context-menu-open');
}
setShowContextMenu(null); setShowContextMenu(null);
}, []); }, []);