Skip to content

Commit a68a061

Browse files
fix(ui): skip auto-scrolling on mouse highlight of workspace
1 parent f76bc97 commit a68a061

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ function WorkspaceHeaderImpl({
121121
const hasInputFocusedRef = useRef(false)
122122
const searchInputRef = useRef<HTMLInputElement>(null)
123123
const workspaceListRef = useRef<HTMLDivElement>(null)
124+
const highlightSourceRef = useRef<'keyboard' | 'mouse'>('keyboard')
124125

125126
const [workspaceSearch, setWorkspaceSearch] = useState('')
126127
const [highlightedIndex, setHighlightedIndex] = useState(0)
@@ -133,6 +134,7 @@ function WorkspaceHeaderImpl({
133134

134135
useEffect(() => {
135136
if (!showSearch || !isWorkspaceMenuOpen) return
137+
if (highlightSourceRef.current !== 'keyboard') return
136138
const el = workspaceListRef.current?.querySelector<HTMLElement>(
137139
`[data-workspace-row-idx="${highlightedIndex}"]`
138140
)
@@ -429,9 +431,11 @@ function WorkspaceHeaderImpl({
429431
if (filteredWorkspaces.length === 0) return
430432
if (e.key === 'ArrowDown') {
431433
e.preventDefault()
434+
highlightSourceRef.current = 'keyboard'
432435
setHighlightedIndex((i) => (i + 1) % filteredWorkspaces.length)
433436
} else if (e.key === 'ArrowUp') {
434437
e.preventDefault()
438+
highlightSourceRef.current = 'keyboard'
435439
setHighlightedIndex(
436440
(i) => (i - 1 + filteredWorkspaces.length) % filteredWorkspaces.length
437441
)
@@ -466,7 +470,14 @@ function WorkspaceHeaderImpl({
466470
<div
467471
key={workspace.id}
468472
data-workspace-row-idx={showSearch ? idx : undefined}
469-
onMouseEnter={showSearch ? () => setHighlightedIndex(idx) : undefined}
473+
onMouseEnter={
474+
showSearch
475+
? () => {
476+
highlightSourceRef.current = 'mouse'
477+
setHighlightedIndex(idx)
478+
}
479+
: undefined
480+
}
470481
>
471482
{editingWorkspaceId === workspace.id ? (
472483
<div

0 commit comments

Comments
 (0)