Skip to content

Build your personal knowledge base with Trilium Notes

fix(attributes): type the autocomplete dropdown position as CSS properties

Elian Doran5817b56d034d
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
index c6e38ea9af..793d86dbc7 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
@@ -23,8 +23,8 @@ import FormTextBox, { FormTextBoxWithUnit } from "../react/FormTextBox.jsx";
import HelpButton from "../react/HelpButton.jsx";
import NoteAutocomplete from "../react/NoteAutocomplete.jsx";
import NoteLink from "../react/NoteLink.jsx";
-import { disposeReactWidget, ParentComponent, renderReactWidgetAtElement } from "../react/react_utils.jsx";
import RawHtml from "../react/RawHtml.jsx";
+import { disposeReactWidget, ParentComponent, renderReactWidgetAtElement } from "../react/react_utils.jsx";
import { ATTR_HELP } from "./attr_help.js";
export interface AttributeDetailOpts {
@@ -431,7 +431,7 @@ function AttributeForm({ opts, attrType, currentNoteId, onAttributesChanged, onS
{isDefinition(attrType) && (
<tr class="attr-row-promoted" title={t("attribute_detail.promoted_title")}>
- <th></th>
+ <th />
<td>
<FormCheckbox
label={t("attribute_detail.promoted")}
@@ -530,7 +530,7 @@ function AttributeForm({ opts, attrType, currentNoteId, onAttributesChanged, onS
)}
<tr title={t("attribute_detail.inheritable_title")}>
- <th></th>
+ <th />
<td>
<FormCheckbox
label={t("attribute_detail.inheritable")}
diff --git a/apps/client/src/widgets/react/FormAutocomplete.tsx b/apps/client/src/widgets/react/FormAutocomplete.tsx
index 14b861908c..fdd8bb91db 100644
--- a/apps/client/src/widgets/react/FormAutocomplete.tsx
+++ b/apps/client/src/widgets/react/FormAutocomplete.tsx
@@ -1,7 +1,7 @@
import "./FormAutocomplete.css";
import type { TargetedKeyboardEvent } from "preact";
-import { createPortal } from "preact/compat";
+import { createPortal, type CSSProperties } from "preact/compat";
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
import FormTextBox from "./FormTextBox";
@@ -42,7 +42,7 @@ export default function FormAutocomplete({ currentValue, onChange, source, openO
const [ isOpen, setIsOpen ] = useState(false);
const [ items, setItems ] = useState<string[]>([]);
const [ activeIndex, setActiveIndex ] = useState(-1);
- const [ position, setPosition ] = useState<DropdownPosition>();
+ const [ position, setPosition ] = useState<CSSProperties>();
// Discards responses of queries that were superseded while in flight.
const latestQuery = useRef(0);
@@ -196,19 +196,12 @@ export default function FormAutocomplete({ currentValue, onChange, source, openO
);
}
-interface DropdownPosition {
- left: number;
- top: number;
- width: number;
- maxHeight: number;
-}
-
/**
* Places the dropdown under the input, flipping above it only when the space below is too small to
* be useful. Preferring below matters for inputs sitting in a panel docked to the bottom of the
* screen: the room under them is limited but ample, while flipping would cover the panel itself.
*/
-function computeDropdownPosition(input: HTMLElement): DropdownPosition {
+function computeDropdownPosition(input: HTMLElement): CSSProperties {
const rect = input.getBoundingClientRect();
const viewportHeight = document.documentElement.clientHeight;
const spaceBelow = viewportHeight - rect.bottom - VIEWPORT_MARGIN;
@@ -218,9 +211,9 @@ function computeDropdownPosition(input: HTMLElement): DropdownPosition {
const maxHeight = Math.min(MAX_DROPDOWN_HEIGHT, Math.max(available, 0));
return {
- left: rect.left,
- top: flipAbove ? rect.top - maxHeight : rect.bottom,
- width: rect.width,
- maxHeight
+ left: `${rect.left}px`,
+ top: `${flipAbove ? rect.top - maxHeight : rect.bottom}px`,
+ width: `${rect.width}px`,
+ maxHeight: `${maxHeight}px`
};
}