Skip to content

Build your personal knowledge base with Trilium Notes

fix(search): navigate only from the search result title

Elian Doran08972f0af716
diff --git a/apps/client/src/widgets/collections/search/SearchResultCard.tsx b/apps/client/src/widgets/collections/search/SearchResultCard.tsx
index c9aeef4660..a9ebfa0310 100644
--- a/apps/client/src/widgets/collections/search/SearchResultCard.tsx
+++ b/apps/client/src/widgets/collections/search/SearchResultCard.tsx
@@ -39,21 +39,18 @@ export default function SearchResultCard({ noteId, details, loading, highlighted
const hasDetails = !!details || loading;
return (
- <a
+ <div
className={clsx("tn-card-frame", "note-book-card", "search-result-card", "no-tooltip-preview",
note?.getColorClass(), note?.isArchived && "archived")}
- href={href}
data-note-id={noteId}
>
<h5 className="note-book-header">
<Icon className="note-icon" icon={icon} />
<span className="note-book-title">
<span>
- <HighlightedText
- className="search-result-card-title"
- text={title}
- highlightedTokens={highlightedTokens}
- />
+ <a className="search-result-card-title no-tooltip-preview" href={href}>
+ <HighlightedText text={title} highlightedTokens={highlightedTokens} />
+ </a>
{breadcrumb && <NotePath path={breadcrumb} />}
</span>
</span>
@@ -68,7 +65,7 @@ export default function SearchResultCard({ noteId, details, loading, highlighted
/>
</div>
)}
- </a>
+ </div>
);
}
diff --git a/apps/client/src/widgets/collections/search/SearchResultsList.css b/apps/client/src/widgets/collections/search/SearchResultsList.css
index b2fbab8779..2ae2989c38 100644
--- a/apps/client/src/widgets/collections/search/SearchResultsList.css
+++ b/apps/client/src/widgets/collections/search/SearchResultsList.css
@@ -53,14 +53,23 @@
user-select: text;
}
+ /* The grid's press effect belongs to its grid layout, not to a full-width row. */
+ .note-list-container.search-results .search-result-card.note-book-card:active {
+ transform: none;
+ }
+
.search-result-card-title {
font-weight: 500;
overflow-wrap: anywhere;
+ color: inherit;
+ text-decoration: none;
}
.search-result-card-content {
padding: .5rem 1rem 1rem;
font-size: 0.85rem;
+ cursor: text;
+ user-select: text;
}
.search-result-card-snippet {
diff --git a/apps/client/src/widgets/collections/search/SearchResultsList.spec.tsx b/apps/client/src/widgets/collections/search/SearchResultsList.spec.tsx
index 8dc5b33783..8ab0c07153 100644
--- a/apps/client/src/widgets/collections/search/SearchResultsList.spec.tsx
+++ b/apps/client/src/widgets/collections/search/SearchResultsList.spec.tsx
@@ -82,7 +82,7 @@ describe("SearchResultCard", () => {
<SearchResultCard noteId={note.noteId} details={makeDetails()} loading={false} highlightedTokens={["sync"]} />
);
- const link = container.querySelector("a.search-result-card");
+ const link = container.querySelector("a.search-result-card-title");
// The card's href carries the highlighted plain tokens as `searchTerms` so the destination
// type widget can highlight/jump to them via ViewScope.searchTerms.
expect(link?.getAttribute("href")).toBe(`#${note.noteId}?searchTerms=sync`);
@@ -111,13 +111,13 @@ describe("SearchResultCard", () => {
await mount(
<SearchResultCard noteId={note.noteId} details={makeDetails({ matchedTerms: [ "Ktorý" ] })} loading={false} highlightedTokens={[ "ktory" ]} />
);
- expect(container.querySelector("a.search-result-card")?.getAttribute("href"))
+ expect(container.querySelector("a.search-result-card-title")?.getAttribute("href"))
.toBe(calculateHash({ notePath: note.noteId, viewScope: { searchTerms: [ "Ktorý" ] } }));
await mount(
<SearchResultCard noteId={note.noteId} details={makeDetails({ matchedTerms: [] })} loading={false} highlightedTokens={[ "ktory" ]} />
);
- expect(container.querySelector("a.search-result-card")?.getAttribute("href")).toBe(`#${note.noteId}?searchTerms=ktory`);
+ expect(container.querySelector("a.search-result-card-title")?.getAttribute("href")).toBe(`#${note.noteId}?searchTerms=ktory`);
});
it("shows a snippet skeleton while the page's details are still loading", async () => {
@@ -148,6 +148,18 @@ describe("SearchResultCard", () => {
expect(container.querySelector(".search-result-card-snippet.skeleton")).toBeNull();
expect(container.querySelector(".search-result-card-badges")).toBeNull();
});
+
+ it("links only the title, leaving the snippet outside the link", async () => {
+ const note = buildNote({ id: "note1", title: "Meeting notes", type: "text" });
+ await mount(
+ <SearchResultCard noteId={note.noteId} details={makeDetails()} loading={false} highlightedTokens={null} />
+ );
+
+ expect(container.querySelector("a.search-result-card")).toBeNull();
+ expect(container.querySelector("a.search-result-card-title")).not.toBeNull();
+ expect(container.querySelector(".search-result-card-content a")).toBeNull();
+ expect(container.querySelector(".search-result-card-content")?.textContent).toContain("calendar");
+ });
});
describe("SearchResultsList", () => {
@@ -186,7 +198,7 @@ describe("SearchResultsList", () => {
}
function cardHrefs() {
- return [ ...container.querySelectorAll("a.search-result-card") ].map((card) => card.getAttribute("href"));
+ return [ ...container.querySelectorAll("a.search-result-card-title") ].map((card) => card.getAttribute("href"));
}
});