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
fix(attributes): stop the detail popup resizing after it opens
Elian Doran5ef96ad7e961
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.css b/apps/client/src/widgets/attribute_widgets/attribute_detail.cssindex 7774f86ae4..8762954d5c 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.css+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.css@@ -23,8 +23,41 @@vertical-align: middle;}+/*+ * The related notes come from an asynchronous lookup that lands well after the popup has been positioned,+ * and they come and go again as the attribute is edited. The section therefore stays in the DOM and eases+ * its height open and shut, so the popup grows and shrinks instead of snapping to a new size under the+ * pointer. The grid row is what makes an automatic height animatable, the inner wrapper clips the content+ * while it is collapsed, and the delayed visibility drops the links out of the tab order once they are+ * fully hidden.+ */.related-notes-container {+ display: grid;+ grid-template-rows: 0fr;+ margin-top: 0;+ opacity: 0;+ visibility: hidden;+ transition:+ grid-template-rows 200ms ease,+ margin-top 200ms ease,+ opacity 200ms ease,+ visibility 0s linear 200ms;+}++.related-notes-container.expanded {+ grid-template-rows: 1fr;margin-top: 20px;+ opacity: 1;+ visibility: visible;+ transition:+ grid-template-rows 200ms ease,+ margin-top 200ms ease,+ opacity 200ms ease;+}++.related-notes-inner {+ overflow: hidden;+ min-height: 0;}.related-notes-list {diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsxindex 744a2f530f..1dab99adc8 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx@@ -1,6 +1,7 @@import "./attribute_detail.css";import type { DefinitionObject, LabelType, Multiplicity } from "@triliumnext/commons";+import clsx from "clsx";import { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";import appContext from "../../components/app_context.js";@@ -645,9 +646,16 @@ interface SearchRelatedResponse {count: number;}-/** Lists the other notes carrying the same attribute, hidden entirely when there are none. */+interface RelatedNotesResult {+ notePaths: string[];+ /** How many further notes the list does not show, `0` when it shows them all. */+ moreCount: number;+}++/** Lists the other notes carrying the same attribute, collapsed entirely when there are none. */function RelatedNotes({ attribute, currentNoteId }: { attribute: Attribute; currentNoteId?: string | null }) {- const [ related, setRelated ] = useState<{ notePaths: string[]; moreCount: number }>();+ const [ related, setRelated ] = useState<RelatedNotesResult>();+ const lastFilled = useRef<RelatedNotesResult>();const latestRequest = useRef(0);const isInitialLookup = useRef(true);const { type, name, value } = attribute;@@ -687,27 +695,34 @@ function RelatedNotes({ attribute, currentNoteId }: { attribute: Attribute; curr// `attribute` is edited in place, so its fields rather than its identity are the real inputs.}, [ type, name, value, currentNoteId ]); // eslint-disable-line react-hooks/exhaustive-deps- if (!related?.notePaths.length) {- return null;+ // The section stays mounted so that the CSS can ease its height: the lookup lands after the popup has+ // been positioned, and mounting it then would snap the popup to a new size. The last non-empty result+ // stays as its content so that collapsing animates as well, rather than emptying out at once.+ const shown = !!related?.notePaths.length;+ if (shown) {+ lastFilled.current = related;}+ const content = lastFilled.current;return (- <div class="related-notes-container">- <h5 class="related-notes-title">- {t("attribute_detail.other_notes_with_name", { attributeType: type, attributeName: name })}- </h5>-- <ul class="related-notes-list">- {related.notePaths.map((notePath) => (- <li key={notePath}><NoteLink notePath={notePath} showNotePath /></li>- ))}- </ul>-- {related.moreCount > 0 && (- <div class="related-notes-more-notes">- {t("attribute_detail.and_more", { count: related.moreCount })}- </div>- )}+ <div class={clsx("related-notes-container", shown && "expanded")}>+ <div class="related-notes-inner">+ <h5 class="related-notes-title">+ {t("attribute_detail.other_notes_with_name", { attributeType: type, attributeName: name })}+ </h5>++ <ul class="related-notes-list">+ {content?.notePaths.map((notePath) => (+ <li key={notePath}><NoteLink notePath={notePath} showNotePath /></li>+ ))}+ </ul>++ {(content?.moreCount ?? 0) > 0 && (+ <div class="related-notes-more-notes">+ {t("attribute_detail.and_more", { count: content?.moreCount })}+ </div>+ )}+ </div></div>);}