Fix clearing a live-but-uncommitted search re-committing the old value

commitFilter now reads the live overrides from a ref that setFilter updates
synchronously, so committing within the same event that changed a filter no
longer sees a stale render closure. antd's Input.Search fires onSearch (before
onChange) when the clear button is clicked, so onSearch now commits the cleared
state instead of closing the dropdown, which had re-committed the still-live
typed value.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 4.8 committed 2026-07-02 22:02:25 +00:00
1 parent 2898fdf5d3
commit 40407e52d6
3 files changed
+29 -12

No files matched your search

+11 -6
View File
@@ -43,12 +43,17 @@ export default function useColumnSearch<T>(
setSelectedKeys(values);
tableState.setFilter(columnKey, values.length ? values : null);
}}
onSearch={() => close()}
onClear={() => {
setSelectedKeys([]);
tableState.setFilter(columnKey, null);
// Clearing is a deliberate action, so write it to the URL right away.
tableState.commitFilter(columnKey, null);
onSearch={value => {
if (value) {
close();
} else {
// antd fires onSearch with an empty value when the clear (X) is clicked
// (before onChange); commit the cleared state instead of closing, which
// would re-commit the still-live typed value.
setSelectedKeys([]);
tableState.setFilter(columnKey, null);
tableState.commitFilter(columnKey, null);
}
}}
/>
</div>