fix(folder): prevent branch submenu from being clipped in scroll area

This commit is contained in:
xintaofei
2026-04-15 13:18:10 +08:00
parent f3630ba48a
commit 3148966371
2 changed files with 11 additions and 28 deletions

View File

@@ -146,7 +146,6 @@ export function BranchDropdown({
const [localOpen, setLocalOpen] = useState(false) const [localOpen, setLocalOpen] = useState(false)
const [remoteOpen, setRemoteOpen] = useState(false) const [remoteOpen, setRemoteOpen] = useState(false)
const [confirmAction, setConfirmAction] = useState<ConfirmAction | null>(null) const [confirmAction, setConfirmAction] = useState<ConfirmAction | null>(null)
const [expandedBranch, setExpandedBranch] = useState<string | null>(null)
const [worktreeOpen, setWorktreeOpen] = useState(false) const [worktreeOpen, setWorktreeOpen] = useState(false)
const [worktreeBranchName, setWorktreeBranchName] = useState("") const [worktreeBranchName, setWorktreeBranchName] = useState("")
const [worktreePath, setWorktreePath] = useState("") const [worktreePath, setWorktreePath] = useState("")
@@ -299,7 +298,6 @@ export function BranchDropdown({
if (!open) { if (!open) {
setLocalOpen(false) setLocalOpen(false)
setRemoteOpen(false) setRemoteOpen(false)
setExpandedBranch(null)
} }
} }
@@ -512,27 +510,10 @@ export function BranchDropdown({
} }
return ( return (
<DropdownMenuSub <DropdownMenuSub key={b}>
key={b}
open={expandedBranch === b}
onOpenChange={(open) => {
if (!open) setExpandedBranch(null)
}}
>
<DropdownMenuSubTrigger <DropdownMenuSubTrigger
className="hover:bg-accent hover:text-accent-foreground" className="hover:bg-accent hover:text-accent-foreground"
disabled={loading} disabled={loading}
onClick={() => setExpandedBranch(expandedBranch === b ? null : b)}
onPointerMove={(e) => {
e.preventDefault()
if (expandedBranch !== null && expandedBranch !== b) {
setExpandedBranch(null)
if (document.activeElement instanceof HTMLElement) {
document.activeElement.blur()
}
}
}}
onPointerLeave={(e) => e.preventDefault()}
> >
<BranchIcon className="h-3.5 w-3.5" /> <BranchIcon className="h-3.5 w-3.5" />
{label} {label}

View File

@@ -243,6 +243,7 @@ function DropdownMenuSubContent({
...props ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) { }: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
return ( return (
<DropdownMenuPrimitive.Portal>
<DropdownMenuPrimitive.SubContent <DropdownMenuPrimitive.SubContent
data-slot="dropdown-menu-sub-content" data-slot="dropdown-menu-sub-content"
className={cn( className={cn(
@@ -251,6 +252,7 @@ function DropdownMenuSubContent({
)} )}
{...props} {...props}
/> />
</DropdownMenuPrimitive.Portal>
) )
} }