Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/collections/board/search & filtering: fix some issues
Adorian Doran258fb43917ee
diff --git a/apps/client/src/widgets/collections/board/card.spec.tsx b/apps/client/src/widgets/collections/board/card.spec.tsxindex 2c16a45bf2..cc1aa13785 100644--- a/apps/client/src/widgets/collections/board/card.spec.tsx+++ b/apps/client/src/widgets/collections/board/card.spec.tsx@@ -20,12 +20,22 @@ import { buildNote } from "../../../test/easy-froca";import { ParentComponent } from "../../react/react_utils";import BoardApi from "./api";import BoardView from ".";+import { OutsideFilterBadge } from "./card";// The card menu opens with the shared link items, which reach for the active note context.vi.mock("../../../menus/link_context_menu", () => ({default: { getItems: () => [], handleLinkContextMenuItem: () => {} }}));+// i18next is never initialised under test, so every label would read as undefined. The awaited+// promise is what `command_registry` imports from here, which the board pulls in through the+// autocomplete field.+vi.mock("../../../services/i18n", () => ({+ t: (key: string) => key,+ translationsInitializedPromise: Promise.resolve(),+ getCurrentLanguage: () => "en"+}));+/** Counts how often each card has drawn, which is what the memo boundary around it decides. */const draws = vi.hoisted(() => new Map<string, number>());vi.mock("../../attribute_widgets/UserAttributesList", () => ({@@ -375,6 +385,26 @@ describe("Board card", () => {const cardIcon = (noteId: string) => card(noteId).querySelector(".title .icon")?.className ?? "";});+/**+ * The clock a card carries while it is drawn although the filter misses it. The tooltip reaches+ * only a reader who points at it, so the name has to be on the element as well.+ */+describe("OutsideFilterBadge", () => {+ it("names itself for assistive technology", () => {+ const container = document.body.appendChild(document.createElement("div"));+ try {+ act(() => render(<OutsideFilterBadge />, container));++ const badge = container.querySelector(".board-note-outside-filter");+ expect(badge?.getAttribute("role")).toBe("img");+ expect(badge?.getAttribute("aria-label")).toBe("board_view.card-outside-filter");+ } finally {+ render(null, container);+ container.remove();+ }+ });+});+/** Drains the async chain inside the board's `refresh()` plus any re-render it queues. */async function settle() {await act(async () => {diff --git a/apps/client/src/widgets/collections/board/card.tsx b/apps/client/src/widgets/collections/board/card.tsxindex 48d50fedba..c07ebbbcfe 100644--- a/apps/client/src/widgets/collections/board/card.tsx+++ b/apps/client/src/widgets/collections/board/card.tsx@@ -1,4 +1,3 @@-import type { Tooltip } from "bootstrap";import { memo } from "preact/compat";import {useCallback, useContext, useEffect, useLayoutEffect, useRef, useState@@ -18,9 +17,9 @@ import UserAttributesDisplay from "../../attribute_widgets/UserAttributesList";import { parseNavigationStateFromUrl } from "../../../services/link";import { FLIP_SETTLE_MS } from "../../react/flip";import {- useNoteColorClass, useNoteIcon, useNoteLabel, useNoteLabelBoolean, useStaticTooltip,- useTriliumEvent+ useNoteColorClass, useNoteIcon, useNoteLabel, useNoteLabelBoolean, useTriliumEvent} from "../../react/hooks";+import { TooltipIcon } from "../../react/Icon";import { HighlightedText } from "../../react/RawHtml";function Card({@@ -236,20 +235,25 @@ function Card({)}-/** Marks a card drawn although the filter does not match it, which one just made here is. */-function OutsideFilterBadge() {- const badgeRef = useRef<HTMLSpanElement>(null);- useStaticTooltip(badgeRef, OUTSIDE_FILTER_TOOLTIP);-- return <span ref={badgeRef} className="board-note-outside-filter icon bx bx-time-five" />;+/**+ * Marks a card drawn although the filter does not match it, which one just made here is.+ *+ * `role="img"` is what carries the label to a reader: a bare span has no role that a name can be+ * given to, and the tooltip alone reaches nobody who is not pointing at it.+ */+export function OutsideFilterBadge() {+ return (+ <TooltipIcon+ className="board-note-outside-filter"+ icon="bx bx-time-five"+ tooltip={t("board_view.card-outside-filter")}+ tooltipPosition="bottom"+ role="img"+ aria-label={t("board_view.card-outside-filter")}+ />+ );}-const OUTSIDE_FILTER_TOOLTIP: Partial<Tooltip.Options> = {- title: t("board_view.card-outside-filter"),- placement: "bottom",- animation: false-};-/*** Memoized because a board holds hundreds of these and most redraws change none of them: a drag* moves one card, and the rest receive the same props they already had.diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.cssindex 6838bab0a9..eab01e18dd 100644--- a/apps/client/src/widgets/collections/board/index.css+++ b/apps/client/src/widgets/collections/board/index.css@@ -370,6 +370,13 @@ body.mobile .board-view-container .board-add-column {above it takes that place and moves the card down by it. */margin-block: 0 0.65em;transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.15s ease;++ .board-note-outside-filter {+ color: var(--muted-text-color);+ font-size: 1.1em;+ line-height: 1;+ cursor: default;+ }}.board-view-container .board-column.board-column-archived {@@ -401,13 +408,6 @@ body.mobile .board-view-container .board-add-column {}}-.board-view-container .board-note .board-note-outside-filter {- color: var(--muted-text-color);- font-size: 1.1em;- line-height: 1;- cursor: default;-}-.board-view-container .board-note > .title > .icon {flex: none;display: flex;diff --git a/apps/client/src/widgets/react/Icon.tsx b/apps/client/src/widgets/react/Icon.tsxindex c42253dad1..58e4437a3e 100644--- a/apps/client/src/widgets/react/Icon.tsx+++ b/apps/client/src/widgets/react/Icon.tsx@@ -5,7 +5,8 @@ import { useRef } from "preact/hooks";import { isMobile } from "../../services/utils";import { useStaticTooltip } from "./hooks";-interface IconProps extends Pick<HTMLAttributes<HTMLSpanElement>, "className" | "onClick" | "title" | "style"> {+interface IconProps extends Pick<HTMLAttributes<HTMLSpanElement>,+ "className" | "onClick" | "title" | "style" | "role" | "aria-label"> {icon?: string;className?: string;}