diff --git a/src/components/SearchInput.js b/src/components/SearchInput.js index 8a8644d6..672e520a 100644 --- a/src/components/SearchInput.js +++ b/src/components/SearchInput.js @@ -19,6 +19,20 @@ function SearchInput({ placeholder, value, onChange, ...props }) { return () => window.removeEventListener('keydown', handleKeyDown) }, []) + function handleChange(event) { + const currentCaret = inputElement.current; + const caretPosition = currentCaret.selectionStart; // will Save caret position + + if (onChange) { + onChange(event.target.value); // Update the value + } + + // Restore caret position after value update + setTimeout(() => { + currentCaret.setSelectionRange(caretPosition, caretPosition); + }, 0); + } + return (