8000 fix(ui): caret dropdown clipped by overflow:hidden ancestors by schroldgames · Pull Request #52 · amirlehmam/wmux · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 58 additions & 38 deletions src/renderer/components/SplitPane/SurfaceTabBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect, useRef, useCallback } from 'react';
import { createPortal } from 'react-dom';
import { SurfaceRef, SurfaceId, PaneId, WorkspaceId, QuickLaunchProfile } from '../../../shared/types';
import { useStore } from '../../store';

Expand Down Expand Up @@ -83,8 +84,10 @@ export default function SurfaceTabBar({
const [renamingId, setRenamingId] = useState<SurfaceId | null>(null);
const [renameValue, setRenameValue] = useState('');
const [newMenuOpen, setNewMenuOpen] = useState(false);
const [menuPos, setMenuPos] = useState<{ top: number; left: number } | null>(null);
const renameInputRef = useRef<HTMLInputElement>(null);
const newMenuRef = useRef<HTMLDivElement>(null);
const caretRef = useRef<HTMLButtonElement>(null);
const agentMeta = useStore((state) => state.agentMeta);
const activeWorkspaceId = useStore((state) => state.activeWorkspaceId);
const renameSurface = useStore((state) => state.renameSurface);
Expand Down Expand Up @@ -129,11 +132,15 @@ export default function SurfaceTabBar({
}
}, [renamingId]);

// Close the "new surface" menu on outside click or Escape
// Close the "new surface" menu on outside click or Escape.
// Exclude both the dropdown portal and the caret button — the caret's own
// click handler toggles the menu, so a mousedown there must not also close it.
useEffect(() => {
if (!newMenuOpen) return;
const MouseEvent) => {
if (newMenuRef.current && !newMenuRef.current.contains(e.target as Node)) setNewMenuOpen(false);
const inMenu = newMenuRef.current?.contains(e.target as Node);
const inCaret = caretRef.current?.contains(e.target as Node);
if (!inMenu && !inCaret) setNewMenuOpen(false);
};
const KeyboardEvent) => { if (e.key === 'Escape') setNewMenuOpen(false); };
document.addEventListener('mousedown', onDown);
Expand Down Expand Up @@ -282,52 +289,65 @@ export default function SurfaceTabBar({
{onNewTyped && (
<div className="surface-tab-bar__new-menu-wrap" ref={newMenuRef}>
<button
ref={caretRef}
className="surface-tab-bar__new-caret"
=> setNewMenuOpen((v) => !v)}
=> {
if (!newMenuOpen && caretRef.current) {
const rect = caretRef.current.getBoundingClientRect();
setMenuPos({ top: rect.bottom, left: rect.left });
}
setNewMenuOpen((v) => !v);
}}
tabIndex={-1}
aria-haspopup="menu"
aria-expanded={newMenuOpen}
title="New tab type…"
>
▾
</button>
{newMenuOpen && (
<div className="surface-tab-bar__new-menu" role="menu">
<button role="menuitem" => pickNew('terminal')}>
<span className="surface-tab-bar__new-menu-icon">{surfaceIcon('terminal', false)}</span> Terminal
</button>
<button role="menuitem" => pickNew('browser')}>
<span className="surface-tab-bar__new-menu-icon">{surfaceIcon('browser', false)}</span> Browser
</button>
<button role="menuitem" => pickNew('markdown')}>
<span className="surface-tab-bar__new-menu-icon">{surfaceIcon('markdown', false)}</span> Markdown
</button>
{profiles && profiles.length > 0 && (
<>
<div className="surface-tab-bar__new-menu-sep" role="separator" />
{profiles.map((profile) => (
<button
key={profile.id}
role="menuitem"
className="surface-tab-bar__new-menu-profile"
=> pickProfile(profile)}
title={profile.source === 'project' ? 'Project profile (.wmux.json)' : 'Global profile'}
>
<span className="surface-tab-bar__new-menu-icon">
{profile.icon || surfaceIcon(profile.type, false)}
</span>
<span className="surface-tab-bar__new-menu-profile-name">{profile.name}</span>
{profile.source === 'project' && (
<span className="surface-tab-bar__new-menu-badge">project</span>
)}
</button>
))}
</>
)}
</div>
)}
</div>
)}
{newMenuOpen && menuPos && onNewTyped && createPortal(
<div
ref={newMenuRef}
className="surface-tab-bar__new-menu"
role="menu"
style={{ position: 'fixed', top: menuPos.top, left: menuPos.left }}
>
<button role="menuitem" => pickNew('terminal')}>
<span className="surface-tab-bar__new-menu-icon">{surfaceIcon('terminal', false)}</span> Terminal
</button>
<button role="menuitem" => pickNew('browser')}>
<span className="surface-tab-bar__new-menu-icon">{surfaceIcon('browser', false)}</span> Browser
</button>
<button role="menuitem" => pickNew('markdown')}>
<span className="surface-tab-bar__new-menu-icon">{surfaceIcon('markdown', false)}</span> Markdown
</button>
{profiles && profiles.length > 0 && (
<>
<div className="surface-tab-bar__new-menu-sep" role="separator" />
{profiles.map((profile) => (
<button
key={profile.id}
role="menuitem"
className="surface-tab-bar__new-menu-profile"
=> pickProfile(profile)}
title={profile.source === 'project' ? 'Project profile (.wmux.json)' : 'Global profile'}
>
<span className="surface-tab-bar__new-menu-icon">
{profile.icon || surfaceIcon(profile.type, false)}
</span>
<span className="surface-tab-bar__new-menu-profile-name">{profile.name}</span>
{profile.source === 'project' && (
<span className="surface-tab-bar__new-menu-badge">project</span>
)}
</button>
))}
</>
)}
</div>,
document.body
)}
{onSplitRight && (
<button
className="surface-tab-bar__split-btn"
Expand Down
5 changes: 1 addition & 4 deletions src/renderer/styles/splitpane.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@
}
.surface-tab-bar__new-caret:hover { color: #fff; background: rgba(255,255,255,0.08); }
.surface-tab-bar__new-menu {
position: absolute;
top: 30px;
left: 0;
z-index: 50;
z-index: 9999;
min-width: 150px;
padding: 4px;
background: #1c1c1c;
Expand Down
0