Skip to content

Build your personal knowledge base with Trilium Notes

feat(options): make the page title header self-contained

Elian Doran7fc1d07387df
diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.tsx b/apps/client/src/widgets/dialogs/OptionsDialog.tsx
index 280a6ce98e..71897e916f 100644
--- a/apps/client/src/widgets/dialogs/OptionsDialog.tsx
+++ b/apps/client/src/widgets/dialogs/OptionsDialog.tsx
@@ -14,7 +14,6 @@ import FormList, { FormListItem } from "../react/FormList";
import { useChildNotes, useContainedLinkNavigation, useMobileMasterDetail, useNoteContext, useTriliumEvent } from "../react/hooks";
import Modal from "../react/Modal";
import { NoteContextContext, ParentComponent } from "../react/react_utils";
-import { ShowOptionsPageTitleContext } from "../type_widgets/options/components/OptionsPageHeader";
import SettingsNavigation from "../type_widgets/options/components/SettingsNavigation";
/** The settings page shown when no specific section was requested and none was viewed yet this session. */
@@ -64,49 +63,44 @@ export default function OptionsDialog() {
return (
<NoteContextContext.Provider value={noteContext}>
- {/* On desktop/tablet the dialog hides the note's own title, so each settings page renders
- its title in its OptionsPageHeader. In the mobile master-detail flow the modal header
- shows the title instead, so the page header there contributes only its actions. */}
- <ShowOptionsPageTitleContext.Provider value={!isMasterDetail}>
- <Modal
- modalRef={modalRef}
- title={t("options.title")}
- header={isMasterDetail && (mobileView === "page" ? <MobilePageHeader onBack={() => switchMobileView("list")} /> : <MobilePageHeader />)}
- sidebar={isMasterDetail ? undefined : <SettingsSidebar />}
- isFullPageOnMobile
- customTitleBarButtons={!isMobile ? [{
- iconClassName: "bx-expand-alt",
- title: t("popup-editor.maximize"),
- onClick: async () => {
- if (!noteContext.noteId) return;
- const { noteId, hoistedNoteId } = noteContext;
- await appContext.tabManager.openInNewTab(noteId, hoistedNoteId, true);
- setShown(false);
- }
- }] : undefined}
- className="options-dialog"
- size="lg"
- show={shown}
- onHidden={() => {
- // Remember the settings page in view so the next open lands on it.
- if (noteContext.noteId) {
- setLastSection(noteContext.noteId);
- }
+ <Modal
+ modalRef={modalRef}
+ title={t("options.title")}
+ header={isMasterDetail && (mobileView === "page" ? <MobilePageHeader onBack={() => switchMobileView("list")} /> : <MobilePageHeader />)}
+ sidebar={isMasterDetail ? undefined : <SettingsSidebar />}
+ isFullPageOnMobile
+ customTitleBarButtons={!isMobile ? [{
+ iconClassName: "bx-expand-alt",
+ title: t("popup-editor.maximize"),
+ onClick: async () => {
+ if (!noteContext.noteId) return;
+ const { noteId, hoistedNoteId } = noteContext;
+ await appContext.tabManager.openInNewTab(noteId, hoistedNoteId, true);
setShown(false);
- }}
- >
- {isMasterDetail && (
- <div className="options-mobile-nav">
- <MobileSettingsList onSelect={(noteId) => {
- void noteContext.setNote(noteId, { keepActiveDialog: true });
- switchMobileView("page");
- }} />
- </div>
- )}
- <SettingsScrollReset modalRef={modalRef} />
- <NoteDetail />
- </Modal>
- </ShowOptionsPageTitleContext.Provider>
+ }
+ }] : undefined}
+ className="options-dialog"
+ size="lg"
+ show={shown}
+ onHidden={() => {
+ // Remember the settings page in view so the next open lands on it.
+ if (noteContext.noteId) {
+ setLastSection(noteContext.noteId);
+ }
+ setShown(false);
+ }}
+ >
+ {isMasterDetail && (
+ <div className="options-mobile-nav">
+ <MobileSettingsList onSelect={(noteId) => {
+ void noteContext.setNote(noteId, { keepActiveDialog: true });
+ switchMobileView("page");
+ }} />
+ </div>
+ )}
+ <SettingsScrollReset modalRef={modalRef} />
+ <NoteDetail />
+ </Modal>
</NoteContextContext.Provider>
);
}
@@ -199,25 +193,28 @@ function MobileSettingsList({ onSelect }: { onSelect: (noteId: string) => void }
}
/**
- * Replaces the static "Options" title on mobile. In the page view it shows a back button returning
- * to the master list followed by the title of the page in view; in the list view a decorative
- * settings icon takes the button's place (keeping the same footprint so the title doesn't shift
- * between views) followed by the dialog title.
+ * Replaces the static "Options" title on mobile. In the page view it shows just a back button
+ * returning to the master list — the page title itself is rendered by the page's own
+ * {@link OptionsPageHeader} below. In the list view a decorative settings icon and the dialog title
+ * take its place.
*/
function MobilePageHeader({ onBack }: { onBack?: () => void }) {
- const { note } = useNoteContext();
- return (
- <div className="options-mobile-page-header">
- {onBack ? (
+ if (onBack) {
+ return (
+ <div className="options-mobile-page-header">
<ActionButton
icon="bx bx-chevron-left"
text={t("options.back")}
onClick={onBack}
/>
- ) : (
- <span className="options-header-icon icon-action bx bx-cog" aria-hidden="true" />
- )}
- <h5 className="options-mobile-page-title">{onBack ? note?.title : t("options.title")}</h5>
+ </div>
+ );
+ }
+
+ return (
+ <div className="options-mobile-page-header">
+ <span className="options-header-icon icon-action bx bx-cog" aria-hidden="true" />
+ <h5 className="options-mobile-page-title">{t("options.title")}</h5>
</div>
);
}
diff --git a/apps/client/src/widgets/layout/InlineTitle.tsx b/apps/client/src/widgets/layout/InlineTitle.tsx
index 8502ac3d48..a04e8be4f7 100644
--- a/apps/client/src/widgets/layout/InlineTitle.tsx
+++ b/apps/client/src/widgets/layout/InlineTitle.tsx
@@ -25,6 +25,7 @@ export default function InlineTitle() {
const { note, parentComponent, viewScope } = useNoteContext();
const type = useNoteProperty(note, "type");
const mime = useNoteProperty(note, "mime");
+ const isOptions = note?.noteId?.startsWith("_options") ?? false;
const [ shown, setShown ] = useState(shouldShow(note, type, viewScope));
const containerRef = useRef<HTMLDivElement>(null);
const [ titleHidden, setTitleHidden ] = useState(false);
@@ -33,6 +34,18 @@ export default function InlineTitle() {
setShown(shouldShow(note, type, viewScope));
}, [ note, type, mime, viewScope ]);
+ // Options pages render their own title (OptionsPageHeader) inside the content, so collapse the
+ // note's own sticky title-row for them — `hide-title` only fades it (keeping its height), which
+ // would leave an empty band above the embedded header, so hide the row outright instead.
+ useLayoutEffect(() => {
+ if (!isOptions) return;
+ const titleRow = parentComponent.$widget[0].closest(".note-split")?.querySelector<HTMLElement>(":scope > .title-row");
+ if (!titleRow) return;
+ const previousDisplay = titleRow.style.display;
+ titleRow.style.display = "none";
+ return () => { titleRow.style.display = previousDisplay; };
+ }, [ isOptions, parentComponent ]);
+
useLayoutEffect(() => {
if (!shown) return;
@@ -74,7 +87,9 @@ export default function InlineTitle() {
function shouldShow(note: FNote | null | undefined, type: NoteType | undefined, viewScope: ViewScope | undefined) {
if (viewScope?.viewMode !== "default") return false;
- if (note?.noteId?.startsWith("_options")) return true;
+ // Options pages provide their own title via OptionsPageHeader, so this inline title stays hidden
+ // for them (and the sticky title-row is hidden too — see the effect in InlineTitle).
+ if (note?.noteId?.startsWith("_options")) return false;
if (note?.isTriliumSqlite()) return false;
if (note?.isMarkdown()) return false;
return type && supportedNoteTypes.has(type);
diff --git a/apps/client/src/widgets/type_widgets/options/components/OptionsPageHeader.css b/apps/client/src/widgets/type_widgets/options/components/OptionsPageHeader.css
index 087381d0d4..fbafc6d493 100644
--- a/apps/client/src/widgets/type_widgets/options/components/OptionsPageHeader.css
+++ b/apps/client/src/widgets/type_widgets/options/components/OptionsPageHeader.css
@@ -66,25 +66,24 @@
min-width: 0;
}
-/* In the settings dialog: a full-width bar that sticks to the top of the scrolling body, painted
- with the modal background so cards scroll cleanly beneath it. */
-.modal.options-dialog .options-page-header {
+/* A full-width bar that sticks to the top of the scrolling content, so cards scroll cleanly beneath
+ it. The background is painted per context (below) so the sticky bar matches its surroundings. */
+.options-page-header {
position: sticky;
top: 0;
z-index: 1;
- background: var(--modal-background-color);
border-bottom: 1px solid var(--main-border-color);
padding-block: 10px;
}
-/* Standalone (page opened in a tab): the note's own title chrome already shows the title, so this is
- just the actions bar. Keep it sticky to the content with the main background. */
-.note-split.options .options-page-header {
- position: sticky;
- top: 0;
- z-index: 1;
+/* In the settings dialog the content area is painted with the modal background. */
+.modal.options-dialog .options-page-header {
+ background: var(--modal-background-color);
+}
+
+/* Standalone (page opened in a tab): the content uses the main background, and this header stands in
+ for the note's own title chrome, which InlineTitle suppresses for options pages. */
+.note-split .options-page-header {
background: var(--main-background-color);
- border-bottom: 1px solid var(--main-border-color);
- padding-block: 8px;
margin-bottom: 1em;
}
diff --git a/apps/client/src/widgets/type_widgets/options/components/OptionsPageHeader.tsx b/apps/client/src/widgets/type_widgets/options/components/OptionsPageHeader.tsx
index 82ab24c5f8..92d0cd4f2b 100644
--- a/apps/client/src/widgets/type_widgets/options/components/OptionsPageHeader.tsx
+++ b/apps/client/src/widgets/type_widgets/options/components/OptionsPageHeader.tsx
@@ -1,19 +1,9 @@
import "./OptionsPageHeader.css";
-import { ComponentChildren, createContext } from "preact";
-import { useContext } from "preact/hooks";
+import { ComponentChildren } from "preact";
import { useNoteContext } from "../../../react/hooks";
-/**
- * Whether an options page's header should render the page title and icon. The settings dialog sets
- * this to `true` on desktop/tablet, where it hides the note's own title chrome and the page header
- * is the only place the title appears. It stays `false` standalone (the note's normal title chrome
- * already shows the title) and in the dialog's mobile master-detail flow (the modal header shows it
- * there), so the header renders only its actions in those cases.
- */
-export const ShowOptionsPageTitleContext = createContext(false);
-
interface OptionsPageHeaderProps {
/**
* Page-specific controls shown on the title row — e.g. a master enable toggle or, for the
@@ -28,30 +18,30 @@ interface OptionsPageHeaderProps {
}
/**
- * The header banner an options page renders at the top of its content. It shows the page title and
- * icon (when {@link ShowOptionsPageTitleContext} is set) beside any page-defined
- * {@link OptionsPageHeaderProps.actions}, with optional {@link OptionsPageHeaderProps.below} content
- * on a full-width row underneath. The same component is used in the settings dialog (where it sticks
- * to the top as a full-width bar — see the `.modal.options-dialog` styling) and standalone in a tab
- * (`.note-split.options`), so each page owns its header in both contexts.
+ * The header banner an options page renders at the top of its content: the page title and icon
+ * beside any page-defined {@link OptionsPageHeaderProps.actions}, with optional
+ * {@link OptionsPageHeaderProps.below} content on a full-width row underneath.
+ *
+ * This header is the page's title everywhere it renders — in the settings dialog, and (for a page
+ * opened standalone in a tab) in place of the note's own title chrome, which `InlineTitle` suppresses
+ * for options pages. The sticky-bar styling differs per context (see the CSS), but each page owns its
+ * header the same way in all of them.
*/
export default function OptionsPageHeader({ actions, below }: OptionsPageHeaderProps) {
const { note } = useNoteContext();
- const showTitle = useContext(ShowOptionsPageTitleContext);
- const titleNote = showTitle ? note : null;
- // Nothing to render: no title belongs here and the page provided no content.
- if (!titleNote && !actions && !below) return null;
+ // Nothing to render: the note isn't available yet and the page provided no content.
+ if (!note && !actions && !below) return null;
return (
<div className="options-page-header">
<div className="options-page-header-inner">
- {(titleNote || actions) && (
+ {(note || actions) && (
<div className="options-page-header-main">
- {titleNote && (
+ {note && (
<div className="options-page-header-titles">
- <span className={`options-page-header-icon ${titleNote.getIcon()}`} aria-hidden="true" />
- <h2 className="options-page-header-title">{titleNote.title}</h2>
+ <span className={`options-page-header-icon ${note.getIcon()}`} aria-hidden="true" />
+ <h2 className="options-page-header-title">{note.title}</h2>
</div>
)}
{actions && <div className="options-page-header-actions">{actions}</div>}