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
style(autocomplete): widen the note list past a narrow field
Elian Doran2fe45826c9de
diff --git a/apps/client/src/widgets/react/NoteAutocomplete.css b/apps/client/src/widgets/react/NoteAutocomplete.cssindex b57909abc4..524692ab5d 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.css+++ b/apps/client/src/widgets/react/NoteAutocomplete.css@@ -36,9 +36,15 @@}}+/* Twice `VIEWPORT_PADDING` in Popup.tsx, whose `shift()` then keeps the list on screen. */+.note-autocomplete-menu {+ max-width: calc(100vw - 10px);+}+.note-autocomplete-menu .dropdown-item {- /* Outranks Bootstrap's `nowrap`, so a long note path wraps within the field's width. */+ /* Outranks Bootstrap's `nowrap`, so a long note path wraps within the list's width. */white-space: normal;+ overflow-wrap: anywhere;.search-result-attributes {display: block;diff --git a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsxindex 4800e7c57d..552af60ac4 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx@@ -644,20 +644,33 @@ describe("NoteAutocomplete's suggestion list", () => {const input = await mount();const group = input.closest(".input-group");if (!group) throw new Error("no input group rendered");- group.getBoundingClientRect = () => DOMRect.fromRect({ width: 320, height: 30 });- input.getBoundingClientRect = () => DOMRect.fromRect({ width: 200, height: 30 });+ group.getBoundingClientRect = () => DOMRect.fromRect({ width: 720, height: 30 });+ input.getBoundingClientRect = () => DOMRect.fromRect({ width: 600, height: 30 });await type(input, "a");- expect(document.querySelector<HTMLElement>(".note-autocomplete-menu")?.style.width).toBe("320px");+ expect(document.querySelector<HTMLElement>(".note-autocomplete-menu")?.style.width).toBe("720px");});it("spans the element a host anchors it to instead", async () => {const frame = document.createElement("div");- frame.getBoundingClientRect = () => DOMRect.fromRect({ width: 480, height: 30 });+ frame.getBoundingClientRect = () => DOMRect.fromRect({ width: 680, height: 30 });const input = await mount({ anchorRef: { current: frame } });await type(input, "a");- expect(document.querySelector<HTMLElement>(".note-autocomplete-menu")?.style.width).toBe("480px");+ expect(document.querySelector<HTMLElement>(".note-autocomplete-menu")?.style.width).toBe("680px");+ });++ it("widens past a narrow field, and spans a wide one", async () => {+ const input = await mount();+ const group = input.closest(".input-group");+ if (!group) throw new Error("no input group rendered");+ group.getBoundingClientRect = () => DOMRect.fromRect({ width: 320, height: 30 });+ await type(input, "a");+ expect(document.querySelector<HTMLElement>(".note-autocomplete-menu")?.style.width).toBe("500px");++ group.getBoundingClientRect = () => DOMRect.fromRect({ width: 640, height: 30 });+ await type(input, "al");+ expect(document.querySelector<HTMLElement>(".note-autocomplete-menu")?.style.width).toBe("640px");});it("picks a clicked note", async () => {diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsxindex bd068676e4..45e3279775 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx@@ -16,6 +16,9 @@ import Icon from "./Icon";import Popup from "./Popup";import RawHtml from "./RawHtml";+/** Wide enough for a note path a few levels deep to fit on one line. */+const DROPDOWN_MIN_WIDTH = 500;+export interface NoteAutocompleteProps {id?: string;inputRef?: RefObject<HTMLInputElement>;@@ -312,8 +315,8 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,placement="bottom-start"// The pointer moves the highlighted row, so `:hover` marks no second one.className="dropdown-menu show tn-dropdown-menu tn-menu-keyboard note-autocomplete-menu"- // The list spans the whole field, buttons included.- style={{ width: `${anchor.getBoundingClientRect().width}px` }}+ // The list spans the whole field, buttons included, and widens past a narrow one.+ style={{ width: `${Math.max(anchor.getBoundingClientRect().width, DROPDOWN_MIN_WIDTH)}px` }}escapeDismisses={false}onDismiss={autocomplete.close}>