Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager: add a clear button for the filter input field

Adorian Dorand77d275025d9
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index ca4da85e7b..8a08e0a9ad 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2615,6 +2615,7 @@
"category_sharing": "Sharing",
"loading": "Retrieving content...",
"filter_placeholder": "Type text to filter by title...",
+ "clear_filter": "Clear filter",
"no_matches": "No active content matches the filter.",
"toggle_enable": "Enable",
"toggle_disable": "Disable",
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager.tsx b/apps/client/src/widgets/type_widgets/options/content_manager.tsx
index 496ebc9aa5..23cb4a9419 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager.tsx
@@ -144,24 +144,42 @@ export default function ContentManagerSettings({ note }: TypeWidgetProps) {
const [ appliedFilter, setAppliedFilter ] = useState("");
const categories = useCategoryNotes(sortOrder as ContentSortOrder, appliedFilter);
+ const filterRef = useRef<HTMLInputElement>(null);
+
// Typing stays instant while the searches only re-run once the user pauses.
const applyFilter = useMemo(() => debounce(setAppliedFilter, FILTER_DEBOUNCE_MS), []);
useEffect(() => () => applyFilter.clear(), [ applyFilter ]);
+ const clearFilter = useCallback(() => {
+ // Drop any pending debounced call, otherwise the text just cleared would be re-applied.
+ applyFilter.clear();
+ setTypedFilter("");
+ setAppliedFilter("");
+ filterRef.current?.focus();
+ }, [ applyFilter ]);
+
return (
<>
<OptionsPageHeader />
<div className="content-manager-toolbar">
- <FormTextBox
- className="content-manager-filter"
- placeholder={t("content_manager.filter_placeholder")}
- currentValue={typedFilter}
- onChange={(newValue) => {
- setTypedFilter(newValue);
- applyFilter(newValue);
- }}
- />
+ <div className="input-group content-manager-filter">
+ <FormTextBox
+ inputRef={filterRef}
+ placeholder={t("content_manager.filter_placeholder")}
+ currentValue={typedFilter}
+ onChange={(newValue) => {
+ setTypedFilter(newValue);
+ applyFilter(newValue);
+ }}
+ />
+ <button
+ type="button"
+ className="input-group-text input-clearer-button bx bxs-tag-x"
+ title={t("content_manager.clear_filter")}
+ onClick={clearFilter}
+ />
+ </div>
<span className="content-manager-toolbar-label">{t("content_manager.sort_order")}</span>
<SortOrderSelect currentValue={sortOrder} onChange={(newValue) => void setSortOrder(newValue)} />
</div>