Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board/search & filtering: tweak the search field

Adorian Dorand013f2443c89
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 73404ea99a..4fc992e9f1 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4197,7 +4197,6 @@
},
"collection_filter": {
"placeholder": "Filter...",
- "tooltip": "Narrows the collection to the notes matching a search query. Press Enter or the search button to apply; clear the box to show everything again.",
"clear": "Clear the filter",
"fetch-error": "The filter could not be run.",
"submit": "Apply the filter"
diff --git a/apps/client/src/widgets/collections/collection_filter.css b/apps/client/src/widgets/collections/collection_filter.css
index 872a30bb99..5b379e9793 100644
--- a/apps/client/src/widgets/collections/collection_filter.css
+++ b/apps/client/src/widgets/collections/collection_filter.css
@@ -35,7 +35,7 @@
display: inline-block;
position: relative;
- width: clamp(110px, 16vw, 200px);
+ width: clamp(138px, 20vw, 250px);
border: 1px solid transparent;
border-radius: 6px;
background: var(--collection-filter-background);
diff --git a/apps/client/src/widgets/collections/collection_filter.spec.tsx b/apps/client/src/widgets/collections/collection_filter.spec.tsx
index 40692132bd..4cd7baf0f9 100644
--- a/apps/client/src/widgets/collections/collection_filter.spec.tsx
+++ b/apps/client/src/widgets/collections/collection_filter.spec.tsx
@@ -435,10 +435,9 @@ describe("CollectionFilterInput", () => {
expect(filter.setQuery).toHaveBeenCalledWith("#done");
});
- it("puts the clear button before the search button", async () => {
- const { input } = mountInput();
+ it("puts the clear button before the search button", () => {
+ mountInput({ query: "#done" });
- await act(async () => type(input, "#done"));
const buttons = [ ...container.querySelectorAll("button") ].map(button => button.className);
const clear = buttons.findIndex(name => name.includes("collection-filter-clear"));
const submit = buttons.findIndex(name => name.includes("collection-filter-submit"));
@@ -457,16 +456,22 @@ describe("CollectionFilterInput", () => {
expect(filter.setQuery).toHaveBeenCalledWith("");
});
- it("shows the box as active and offers no clear button while empty and inactive", () => {
- mountInput();
- expect(container.querySelector(".collection-filter")?.classList.contains("active")).toBe(false);
+ it("offers no clear button until a filter is in force, whatever is typed", async () => {
+ const { input } = mountInput();
+ const box = () => container.querySelector(".collection-filter");
+ expect(box()?.classList.contains("active")).toBe(false);
+ expect(container.querySelector(".collection-filter-clear")).toBeNull();
+
+ // Typing is not yet a filter, so there is nothing for the button to take away.
+ await act(async () => type(input, "#done"));
expect(container.querySelector(".collection-filter-clear")).toBeNull();
mountInput({ query: "#done" });
- expect(container.querySelector(".collection-filter")?.classList.contains("active")).toBe(true);
+ expect(box()?.classList.contains("active")).toBe(true);
+ expect(container.querySelector(".collection-filter-clear")).not.toBeNull();
});
- // The tooltip opens on hover alone, so the name has to be on the element itself.
+ // The box carries no tooltip, and a placeholder is gone as soon as something is typed.
it("names the box for assistive technology", () => {
const { input } = mountInput();
expect(input.getAttribute("aria-label")).toBe("collection_filter.placeholder");
diff --git a/apps/client/src/widgets/collections/collection_filter.tsx b/apps/client/src/widgets/collections/collection_filter.tsx
index 7cd12453d9..0b2afa0177 100644
--- a/apps/client/src/widgets/collections/collection_filter.tsx
+++ b/apps/client/src/widgets/collections/collection_filter.tsx
@@ -1,7 +1,6 @@
import "./collection_filter.css";
import type { HighlightedTokenInfo } from "@triliumnext/commons";
-import type { Tooltip } from "bootstrap";
import clsx from "clsx";
import { useEffect, useMemo, useRef, useState } from "preact/hooks";
@@ -11,20 +10,11 @@ import type LoadResults from "../../services/load_results";
import searchService from "../../services/search";
import ActionButton from "../react/ActionButton";
import FormTextBox from "../react/FormTextBox";
-import { useStaticTooltip, useTriliumEvent } from "../react/hooks";
+import { useTriliumEvent } from "../react/hooks";
/** How long to wait after a change before re-running the active filter. */
const RERUN_DEBOUNCE_MS = 300;
-// Hover only: the box is typed into, and a tooltip opened by the focus would sit over the header
-// for as long as the query is being written.
-const TOOLTIP_CONFIG: Partial<Tooltip.Options> = {
- title: t("collection_filter.tooltip"),
- placement: "bottom",
- trigger: "hover",
- animation: false
-};
-
export interface CollectionFilter {
/** The submitted query, empty while no filter is active. */
query: string;
@@ -194,7 +184,8 @@ export function useCollectionFilter(note: FNote, {
/**
* The filter box for a collection header. Enter or the search button submits what is typed, which
- * is held here until then so an unrelated redraw cannot apply a half-typed query.
+ * is held here until then so an unrelated redraw cannot apply a half-typed query. The clear button
+ * stands only while a filter is in force, since that is what it takes away.
*/
export function CollectionFilterInput({ filter, placeholder }: {
filter: CollectionFilter;
@@ -203,7 +194,6 @@ export function CollectionFilterInput({ filter, placeholder }: {
}) {
const [ typed, setTyped ] = useState(filter.query);
const inputRef = useRef<HTMLInputElement>(null);
- useStaticTooltip(inputRef, TOOLTIP_CONFIG);
// Adopt a query submitted elsewhere, or the stored one arriving on mount.
useEffect(() => setTyped(filter.query), [ filter.query ]);
@@ -216,8 +206,7 @@ export function CollectionFilterInput({ filter, placeholder }: {
inputRef={inputRef}
currentValue={typed}
placeholder={placeholder ?? t("collection_filter.placeholder")}
- // The tooltip opens on hover alone, so it cannot carry the name to a reader who
- // arrives by keyboard.
+ // A placeholder names the box only until something is typed into it.
aria-label={placeholder ?? t("collection_filter.placeholder")}
onChange={setTyped}
onKeyDown={(e: KeyboardEvent) => {
@@ -233,7 +222,7 @@ export function CollectionFilterInput({ filter, placeholder }: {
}}
/>
<div className="collection-filter-buttons">
- {(!!typed || isActive) && (
+ {isActive && (
<ActionButton
className="collection-filter-clear"
noIconActionClass