From 1cfa12538e9018c38eccaac259cde6abb7aeb77a Mon Sep 17 00:00:00 2001 From: waleed Date: Thu, 5 Feb 2026 14:32:09 -0800 Subject: [PATCH 1/2] fix(cmdk): clean up search modal input handling --- .../components/search-modal/search-modal.tsx | 56 ++++++++----------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx index 5a950c4974..5dc7571fdc 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx @@ -79,7 +79,9 @@ export function SearchModal({ const router = useRouter() const workspaceId = params.workspaceId as string const inputRef = useRef(null) + const listRef = useRef(null) const [mounted, setMounted] = useState(false) + const [search, setSearch] = useState('') const openSettingsModal = useSettingsModalStore((state) => state.openModal) const { config: permissionConfig } = usePermissionConfig() @@ -142,41 +144,18 @@ export function SearchModal({ ) useEffect(() => { - if (open && inputRef.current) { - const nativeInputValueSetter = Object.getOwnPropertyDescriptor( - window.HTMLInputElement.prototype, - 'value' - )?.set - if (nativeInputValueSetter) { - nativeInputValueSetter.call(inputRef.current, '') - inputRef.current.dispatchEvent(new Event('input', { bubbles: true })) - } - inputRef.current.focus() + if (open) { + setSearch('') + inputRef.current?.focus() } }, [open]) - const handleSearchChange = useCallback(() => { - requestAnimationFrame(() => { - const list = document.querySelector('[cmdk-list]') - if (list) { - list.scrollTop = 0 - } - }) - }, []) - - useEffect(() => { - if (!open) return - - const handleKeyDown = (e: KeyboardEvent) => { - if (e.key === 'Escape') { - e.preventDefault() - onOpenChange(false) - } + const handleSearchChange = useCallback((value: string) => { + setSearch(value) + if (listRef.current) { + listRef.current.scrollTop = 0 } - - document.addEventListener('keydown', handleKeyDown) - return () => document.removeEventListener('keydown', handleKeyDown) - }, [open, onOpenChange]) + }, []) const handleBlockSelect = useCallback( (block: SearchBlockItem, type: 'block' | 'trigger' | 'tool') => { @@ -264,7 +243,7 @@ export function SearchModal({ {/* Overlay */}
onOpenChange(false)} @@ -281,16 +260,25 @@ export function SearchModal({ '-translate-x-1/2 fixed top-[15%] left-1/2 z-50 w-[500px] overflow-hidden rounded-[12px] border border-[var(--border)] bg-[var(--surface-4)] shadow-lg', open ? 'visible opacity-100' : 'invisible opacity-0' )} + onKeyDown={(e) => { + if (e.key === 'Escape') { + e.preventDefault() + onOpenChange(false) + } + }} > - + No results found. From f83d9ee5a28cea2fee60dd6a4e9abe1d744edd2a Mon Sep 17 00:00:00 2001 From: waleed Date: Thu, 5 Feb 2026 18:01:33 -0800 Subject: [PATCH 2/2] ack comments --- .../sidebar/components/search-modal/search-modal.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx index 5dc7571fdc..2464f1eced 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal/search-modal.tsx @@ -272,6 +272,12 @@ export function SearchModal({ ref={inputRef} value={search} onValueChange={handleSearchChange} + onKeyDown={(e) => { + if (e.key === 'Escape') { + e.preventDefault() + onOpenChange(false) + } + }} placeholder='Search anything...' className='w-full border-0 border-[var(--border)] border-b bg-transparent px-[12px] py-[10px] font-base text-[15px] text-[var(--text-primary)] placeholder:text-[var(--text-secondary)] focus:outline-none' />