-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(sidebar): collapsed sidebar shows single icons with hover dropdown menus #3588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
db207f9
fix(sidebar): collapsed sidebar shows single icons with hover dropdow…
waleedlatif1 1a42d95
fix(sidebar): truncate long names in collapsed dropdown menus
waleedlatif1 5fee230
fix(sidebar): address PR review — extract components, fix reactive su…
waleedlatif1 cbd33eb
fix(sidebar): support touch/keyboard for collapsed menus, document au…
waleedlatif1 c9f838a
fix(sidebar): remove dead CSS selector for sidebar-collapse-remove
waleedlatif1 e6fde83
fix(sidebar): add aria-label to collapsed menu trigger buttons
waleedlatif1 e8f731e
fix(sidebar): use useLayoutEffect for attribute removal, remove dead …
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...paceId]/w/components/sidebar/components/collapsed-sidebar-menu/collapsed-sidebar-menu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { Folder } from 'lucide-react' | ||
| import Link from 'next/link' | ||
| import { | ||
| DropdownMenu, | ||
| DropdownMenuContent, | ||
| DropdownMenuItem, | ||
| DropdownMenuSub, | ||
| DropdownMenuSubContent, | ||
| DropdownMenuSubTrigger, | ||
| DropdownMenuTrigger, | ||
| } from '@/components/emcn' | ||
| import { cn } from '@/lib/core/utils/cn' | ||
| import type { useHoverMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks' | ||
| import type { FolderTreeNode } from '@/stores/folders/types' | ||
| import type { WorkflowMetadata } from '@/stores/workflows/registry/types' | ||
|
|
||
| interface CollapsedSidebarMenuProps { | ||
| icon: React.ReactNode | ||
| hover: ReturnType<typeof useHoverMenu> | ||
| onClick?: () => void | ||
| ariaLabel?: string | ||
| children: React.ReactNode | ||
| className?: string | ||
| } | ||
|
|
||
| export function CollapsedSidebarMenu({ | ||
| icon, | ||
| hover, | ||
| onClick, | ||
| ariaLabel, | ||
| children, | ||
| className, | ||
| }: CollapsedSidebarMenuProps) { | ||
| return ( | ||
| <div className={cn('flex flex-col px-[8px]', className)}> | ||
| <DropdownMenu | ||
| open={hover.isOpen} | ||
| onOpenChange={(open) => { | ||
| if (open) hover.open() | ||
| else hover.close() | ||
| }} | ||
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| modal={false} | ||
| > | ||
| <div {...hover.triggerProps}> | ||
| <DropdownMenuTrigger asChild> | ||
| <button | ||
| type='button' | ||
| aria-label={ariaLabel} | ||
| className='mx-[2px] flex h-[30px] items-center rounded-[8px] px-[8px] hover:bg-[var(--surface-active)]' | ||
| onClick={onClick} | ||
| > | ||
| {icon} | ||
| </button> | ||
| </DropdownMenuTrigger> | ||
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| <DropdownMenuContent side='right' align='start' sideOffset={8} {...hover.contentProps}> | ||
| {children} | ||
| </DropdownMenuContent> | ||
| </DropdownMenu> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export function CollapsedFolderItems({ | ||
| nodes, | ||
| workflowsByFolder, | ||
| workspaceId, | ||
| }: { | ||
| nodes: FolderTreeNode[] | ||
| workflowsByFolder: Record<string, WorkflowMetadata[]> | ||
| workspaceId: string | ||
| }) { | ||
| return ( | ||
| <> | ||
| {nodes.map((folder) => { | ||
| const folderWorkflows = workflowsByFolder[folder.id] || [] | ||
| const hasChildren = folder.children.length > 0 || folderWorkflows.length > 0 | ||
|
|
||
| if (!hasChildren) { | ||
| return ( | ||
| <DropdownMenuItem key={folder.id} disabled> | ||
| <Folder className='h-[14px] w-[14px]' /> | ||
| <span className='truncate'>{folder.name}</span> | ||
| </DropdownMenuItem> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <DropdownMenuSub key={folder.id}> | ||
| <DropdownMenuSubTrigger> | ||
| <Folder className='h-[14px] w-[14px]' /> | ||
| <span className='truncate'>{folder.name}</span> | ||
| </DropdownMenuSubTrigger> | ||
| <DropdownMenuSubContent> | ||
| <CollapsedFolderItems | ||
| nodes={folder.children} | ||
| workflowsByFolder={workflowsByFolder} | ||
| workspaceId={workspaceId} | ||
| /> | ||
| {folderWorkflows.map((workflow) => ( | ||
| <DropdownMenuItem key={workflow.id} asChild> | ||
| <Link href={`/workspace/${workspaceId}/w/${workflow.id}`}> | ||
| <div | ||
| className='h-[14px] w-[14px] flex-shrink-0 rounded-[3px] border-[2px]' | ||
| style={{ | ||
| backgroundColor: workflow.color, | ||
| borderColor: `${workflow.color}60`, | ||
| backgroundClip: 'padding-box', | ||
| }} | ||
| /> | ||
| <span className='truncate'>{workflow.name}</span> | ||
| </Link> | ||
| </DropdownMenuItem> | ||
| ))} | ||
| </DropdownMenuSubContent> | ||
| </DropdownMenuSub> | ||
| ) | ||
| })} | ||
| </> | ||
| ) | ||
| } | ||
4 changes: 4 additions & 0 deletions
4
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-hover-menu.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { useCallback, useEffect, useMemo, useRef, useState } from 'react' | ||
|
|
||
| const CLOSE_DELAY_MS = 150 | ||
|
|
||
| const preventAutoFocus = (e: Event) => e.preventDefault() | ||
|
|
||
| /** | ||
| * Manages hover-triggered dropdown menu state. | ||
| * Provides handlers for trigger and content mouse events with a delay | ||
| * to prevent flickering when moving between trigger and content. | ||
| */ | ||
| export function useHoverMenu() { | ||
| const [isOpen, setIsOpen] = useState(false) | ||
| const closeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null) | ||
|
|
||
| const cancelClose = useCallback(() => { | ||
| if (closeTimerRef.current) { | ||
| clearTimeout(closeTimerRef.current) | ||
| closeTimerRef.current = null | ||
| } | ||
| }, []) | ||
|
|
||
| useEffect(() => { | ||
| return () => { | ||
| if (closeTimerRef.current) { | ||
| clearTimeout(closeTimerRef.current) | ||
| } | ||
| } | ||
| }, []) | ||
|
|
||
| const scheduleClose = useCallback(() => { | ||
| cancelClose() | ||
| closeTimerRef.current = setTimeout(() => setIsOpen(false), CLOSE_DELAY_MS) | ||
| }, [cancelClose]) | ||
|
|
||
| const open = useCallback(() => { | ||
| cancelClose() | ||
| setIsOpen(true) | ||
| }, [cancelClose]) | ||
|
|
||
| const close = useCallback(() => { | ||
| cancelClose() | ||
| setIsOpen(false) | ||
| }, [cancelClose]) | ||
|
|
||
| const triggerProps = useMemo( | ||
| () => ({ onMouseEnter: open, onMouseLeave: scheduleClose }) as const, | ||
| [open, scheduleClose] | ||
| ) | ||
|
|
||
| const contentProps = useMemo( | ||
| () => | ||
| ({ | ||
| onMouseEnter: cancelClose, | ||
| onMouseLeave: scheduleClose, | ||
| onCloseAutoFocus: preventAutoFocus, | ||
| }) as const, | ||
| [cancelClose, scheduleClose] | ||
| ) | ||
|
|
||
| return { isOpen, open, close, triggerProps, contentProps } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.