Skip to content

Commit 87a335b

Browse files
committed
fix: clear search input when modal reopens
1 parent 44dda1a commit 87a335b

File tree

1 file changed

+10
-13
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/search-modal

1 file changed

+10
-13
lines changed

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function SearchModal({
5959
const workspaceId = params.workspaceId as string
6060
const brand = useBrandConfig()
6161
const inputRef = useRef<HTMLInputElement>(null)
62-
const lastSearchRef = useRef('')
62+
const [search, setSearch] = useState('')
6363
const [mounted, setMounted] = useState(false)
6464

6565
useEffect(() => {
@@ -97,25 +97,21 @@ export function SearchModal({
9797

9898
useEffect(() => {
9999
if (open) {
100-
lastSearchRef.current = ''
100+
setSearch('')
101101
requestAnimationFrame(() => {
102102
inputRef.current?.focus()
103103
})
104104
}
105105
}, [open])
106106

107107
const handleSearchChange = useCallback((value: string) => {
108-
const previousValue = lastSearchRef.current
109-
lastSearchRef.current = value
110-
111-
if (previousValue !== value) {
112-
requestAnimationFrame(() => {
113-
const list = document.querySelector('[cmdk-list]')
114-
if (list) {
115-
list.scrollTop = 0
116-
}
117-
})
118-
}
108+
setSearch(value)
109+
requestAnimationFrame(() => {
110+
const list = document.querySelector('[cmdk-list]')
111+
if (list) {
112+
list.scrollTop = 0
113+
}
114+
})
119115
}, [])
120116

121117
useEffect(() => {
@@ -257,6 +253,7 @@ export function SearchModal({
257253
<Command label='Search' filter={customFilter}>
258254
<Command.Input
259255
ref={inputRef}
256+
value={search}
260257
autoFocus
261258
onValueChange={handleSearchChange}
262259
placeholder='Search anything...'

0 commit comments

Comments
 (0)