Skip to content

Commit 0556297

Browse files
committed
fix(search): restore cmd+k autofocus on the search input
1 parent f76d46b commit 0556297

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

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

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ export function SearchModal({
105105
const atomicBrowserOcclusion = supportsAtomicBrowserPanelOcclusion()
106106
const nativeSurfaceReady = useNativeSurfaceOcclusionReady(open, 'modal')
107107
const visuallyOpen = open && nativeSurfaceReady
108-
const focusReady = atomicBrowserOcclusion ? visuallyOpen : open
109108
const [retainNativeSurfaceOcclusion, setRetainNativeSurfaceOcclusion] = useState(open)
110109
const nativeSurfaceOcclusionActive =
111110
open || (atomicBrowserOcclusion && retainNativeSurfaceOcclusion)
@@ -326,8 +325,12 @@ export function SearchModal({
326325
if (open) setSearch('')
327326
}
328327

328+
/**
329+
* Focus only once the dialog is actually visible: `.focus()` is a no-op while
330+
* the surface still carries `invisible`, and nothing re-focuses afterwards.
331+
*/
329332
useEffect(() => {
330-
if (!focusReady || !inputRef.current) return
333+
if (!visuallyOpen || !inputRef.current) return
331334
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
332335
window.HTMLInputElement.prototype,
333336
'value'
@@ -337,7 +340,7 @@ export function SearchModal({
337340
inputRef.current.dispatchEvent(new Event('input', { bubbles: true }))
338341
}
339342
inputRef.current.focus()
340-
}, [focusReady])
343+
}, [visuallyOpen])
341344

342345
const deferredSearch = useDeferredValue(search)
343346
const deferredSearchRef = useRef(deferredSearch)

0 commit comments

Comments
 (0)