mirror of
https://github.com/coder/coder.git
synced 2025-07-18 13:35:28 +00:00
fix(site): prevent filter input update when focused (#8102)
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user