diff --git a/components/TanstackTable.tsx b/components/TanstackTable.tsx index 157cd3f8..bb6878ce 100644 --- a/components/TanstackTable.tsx +++ b/components/TanstackTable.tsx @@ -197,6 +197,15 @@ export default function TanstackTable({ setColumnFilters(newFilters) } + /** Clears the current filter if it is not set as a chip */ + const clearCurrentFilter = () => { + if (!prevFilters.find(f => f.id === currentFilteredColumn)) { + setColumnFilters(columnFilters.filter(f => f.id !== currentFilteredColumn)) + } + + setSearchQuery("") + } + return ( {enableSearch && ( @@ -221,7 +230,7 @@ export default function TanstackTable({ - @@ -267,13 +276,9 @@ export default function TanstackTable({ }))} defaultValue={filterableColumns[0].id ?? ""} onValueChange={newFilterCol => { - // If not in prevFilters, remove from current filters - if (!prevFilters.find(f => f.id === currentFilteredColumn)) { - setColumnFilters(columnFilters.filter(f => f.id !== currentFilteredColumn)) - } + clearCurrentFilter() setCurrentFilteredColumn(newFilterCol) - setSearchQuery("") setDateStart("") setDateEnd("") }}