fix(site): prevent filter input update when focused (#8102)

This commit is contained in:
Bruno Quaresma
2023-06-20 10:46:04 -03:00
committed by GitHub
parent b8ba287128
commit a47a9b1cfe

View File

@ -148,9 +148,14 @@ export const Filter = ({
const shouldDisplayError = hasError(error) && isApiValidationError(error)
const hasFilterQuery = filter.query !== ""
const [searchQuery, setSearchQuery] = useState(filter.query)
const inputRef = useRef<HTMLInputElement>(null)
useEffect(() => {
// We don't want to update this while the user is typing something or has the focus in the input
const isFocused = document.activeElement === inputRef.current
if (!isFocused) {
setSearchQuery(filter.query)
}
}, [filter.query])
return (
@ -186,6 +191,7 @@ export const Filter = ({
name: "query",
placeholder: "Search...",
value: searchQuery,
ref: inputRef,
onChange: (e) => {
setSearchQuery(e.target.value)
filter.debounceUpdate(e.target.value)