Skip to content
Prev Previous commit
fix(add-documents-modal, combobox): restore useEffect for modal reset…
…, fix combobox dep array

- add-documents-modal: handleOpenChange(true) is dead code in Radix
  controlled mode — restored useEffect watching open for reset-on-open
- combobox: depend on filteredOptions array (not .length) so highlight
  resets when items change even with same count
  • Loading branch information
waleedlatif1 committed Mar 19, 2026
commit 4860ff862d9eb893bafac0c927031af1c626fe20
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,21 @@ export function AddDocumentsModal({
}
}, [files])

/** Resets state on open and handles close with upload guard */
useEffect(() => {
if (open) {
setFiles([])
setFileError(null)
setIsDragging(false)
setDragCounter(0)
setRetryingIndexes(new Set())
clearError()
}
}, [open, clearError])

/** Handles close with upload guard */
const handleOpenChange = useCallback(
(newOpen: boolean) => {
if (newOpen) {
setFiles([])
setFileError(null)
setIsDragging(false)
setDragCounter(0)
setRetryingIndexes(new Set())
clearError()
} else {
if (!newOpen) {
if (isUploading) return
setFiles([])
setFileError(null)
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/components/emcn/components/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,13 @@ const Combobox = memo(
highlightedIndex >= 0 && highlightedIndex < filteredOptions.length ? highlightedIndex : -1
Comment thread
waleedlatif1 marked this conversation as resolved.

/**
* Reset highlighted index when filtered options shrink below it
* Reset highlighted index when filtered options change and index is out of bounds
*/
useEffect(() => {
if (highlightedIndex >= 0 && highlightedIndex >= filteredOptions.length) {
setHighlightedIndex(-1)
}
}, [filteredOptions.length, highlightedIndex])
}, [filteredOptions, highlightedIndex])

/**
* Scroll highlighted option into view
Expand Down
Loading