Skip to content

Build your personal knowledge base with Trilium Notes

fix(mind-map): hold the node panel still as its tabs are switched

Elian Doran3d79d56f8e97
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
index 52414e6721..77fdd69304 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
@@ -33,25 +33,43 @@
border-bottom: 1px solid var(--main-border-color);
}
+/*
+ * Every tab is laid into the same cell, so the panel stands as tall as the tallest of them and
+ * keeps that height whichever is on show. Were each tab to size the panel in turn, switching to the
+ * memo would collapse the panel to the height of one field — pulling the strip up the screen, out
+ * from under the pointer that had just pressed a tab.
+ */
+.mind-map-node-panel .mind-map-node-panel-bodies {
+ display: grid;
+ /* Without it a grid refuses to shrink past its content, and the panel scrolls as a whole. */
+ min-height: 0;
+}
+
/* Each tab holds the padding, rather than the panel: the memo's is its own (see below). */
.mind-map-node-panel .mind-map-node-panel-body {
+ grid-area: 1 / 1;
padding: 15px;
overflow: auto;
- /* Without it a flex item refuses to shrink past its content, and the panel scrolls as a whole. */
+ /* As above, for the tab within the cell. */
min-height: 0;
}
/*
- * The memo is the whole of its tab: it takes the height the panel can spare and grows the panel to
- * a comfortable writing box where there is room, instead of the three lines it had as a field.
+ * The tab not on show keeps its place in the cell rather than leaving it, which is what holds the
+ * height of the panel still. `visibility` and not `display`, whose `none` would give the place up —
+ * it takes the tab out of reach of the pointer, the keyboard and a screen reader all the same.
*/
+.mind-map-node-panel .mind-map-node-panel-body[aria-hidden="true"] {
+ visibility: hidden;
+}
+
+/* The memo is the whole of its tab, so it fills the height the panel took from the fields. */
.mind-map-node-panel .mind-map-node-panel-memo-body {
display: flex;
padding: 8px;
.mind-map-node-memo {
flex: 1;
- min-height: 220px;
max-height: none;
}
}
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
index 027799b2c4..6bd1d45dee 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
@@ -252,6 +252,11 @@ describe("the memo field of the panel", () => {
const openMemoTab = (container: HTMLElement) => openTab(container, "bx-notepad");
const openFormatTab = (container: HTMLElement) => openTab(container, "bx-palette");
+ /** The tabs' bodies, in the order they are laid into the panel — all of them, shown or not. */
+ function tabBodies(container: HTMLElement) {
+ return [ ...container.querySelectorAll('[role="tabpanel"]') ];
+ }
+
/** The icon of the tab on show, which is what the panel says it is showing. */
function activeTabIcon(container: HTMLElement) {
const active = container.querySelector('[role="tab"][aria-selected="true"] .tn-icon');
@@ -284,9 +289,11 @@ describe("the memo field of the panel", () => {
await openMemoTab(panel);
expect(activeTabIcon(panel)).toBe("bx-notepad");
expect(shownMemo(panel)).toBe("<p>About A</p>");
- // The fields are put out of sight rather than taken down, so returning to them is instant
- // and nothing half-typed in them is lost on the way to the memo.
+ // Every tab keeps its place in the panel, the one not on show merely hidden within it: that
+ // is what holds the panel's height still as tabs are switched, and it is also what makes
+ // returning to the fields instant, with nothing half-typed in them lost on the way.
expect(section(panel, SIZE)).toBeTruthy();
+ expect(tabBodies(panel).map((body) => body.getAttribute("aria-hidden"))).toEqual([ "true", "false" ]);
});
it("writes a memo back from behind the other tab, the editor staying up once raised", async () => {
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
index ef3af490c9..efdae10817 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
@@ -2,7 +2,6 @@ import "./NodePanel.css";
import { parseMindMapNoteLink } from "@triliumnext/commons";
import { Dropdown as BootstrapDropdown } from "bootstrap";
-import clsx from "clsx";
import type { MindElixirInstance, NodeObj, TagObj } from "mind-elixir";
import { ComponentChildren } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
@@ -139,125 +138,131 @@ export default function NodePanel({ mind, noteId, nodes }: NodePanelProps) {
onSelect={setActiveTabId}
/>
- <div
- role="tabpanel"
- className={clsx("mind-map-node-panel-body", activeTabId !== "format" && "hidden-ext")}
- >
- <PanelSection label={t("mind-map.font-size")}>
- <SegmentedChoice
- options={buildFontSizeOptions()}
- currentValue={fontSize !== MIXED ? fontSize ?? DEFAULT_FONT_SIZE : MIXED_FONT_SIZE}
- onChange={(fontSize) => patchSelectedNodes({ style: { fontSize } })}
- />
- </PanelSection>
-
- <PanelSection label={t("mind-map.text-color")}>
- <ColorPicker
- presets={NODE_COLORS}
- {...toPickerValue(textColor)}
- // Mind Elixir only ever assigns the style properties it is given and never
- // resets the ones it isn't, so clearing has to blank the property explicitly.
- onChange={(color) => patchSelectedNodes({ style: { color: color ?? "" } })}
- />
- </PanelSection>
-
- <PanelSection label={t("mind-map.background-color")}>
- <ColorPicker
- presets={NODE_BACKGROUND_COLORS}
- {...toPickerValue(backgroundColor)}
- onChange={(color) => patchSelectedNodes({ style: { background: color ?? "" } })}
- />
- </PanelSection>
-
- <PanelSection label={t("mind-map.branch-color")}>
- <ColorPicker
- presets={NODE_COLORS}
- {...toPickerValue(branchColor)}
- onChange={(color) => patchSelectedNodes({ branchColor: color ?? "" })}
- />
- </PanelSection>
-
- <PanelSection
- label={t("mind-map.icons")}
- title={icons.readOnly ? t("mind-map.icons-differ") : undefined}
- >
- <NodeIcons
- icons={icons.values}
- readOnly={icons.readOnly}
- onChange={(icons) => patchSelectedNodes({ icons })}
- />
- </PanelSection>
-
- <PanelSection
- label={t("mind-map.image")}
- title={image === MIXED ? t("mind-map.images-differ") : undefined}
- >
- <NodeImage
- hasImage={!!image}
- indeterminate={image === MIXED}
- width={imageWidth !== MIXED && imageWidth ? Number(imageWidth) : null}
- shape={imageShape !== MIXED ? imageShape : null}
- onShape={(shape) => void shapeImages(shape)}
- // A node carries one picture, so what is taken in takes the place of what was
- // there, at the size it comes in at.
- onPick={(file) => void takeInImage(file)}
- // Derived per node: the nodes are set to the same width, but each keeps the
- // proportions of the picture it carries.
- onResize={(width) => patchSelectedNodes((node) => ({
- image: node.image && fitNodeImage(node.image, width)
- }))}
- onRemove={() => patchSelectedNodes({ image: undefined })}
- />
- </PanelSection>
-
- <PanelSection
- label={t("mind-map.node-link")}
- title={link === MIXED ? t("mind-map.links-differ") : undefined}
- >
- <NodeLink
- currentValue={link !== MIXED ? link : null}
- indeterminate={link === MIXED}
- // A node carries one link, so what is picked takes the place of what was there.
- // Clearing blanks the property, Mind Elixir only ever assigning the ones it is
- // given (see the colors above).
- onChange={(link) => patchSelectedNodes({ hyperLink: link ?? "" })}
- />
- </PanelSection>
-
- <PanelSection
- label={t("mind-map.tags")}
- title={tags.readOnly ? t("mind-map.tags-differ") : undefined}
- >
- <ValuesInput
- labelType="text"
- values={tags.texts}
- placeholder={t("mind-map.tags-placeholder")}
- addButtonText={t("mind-map.add-tag")}
- removeButtonText={t("mind-map.remove-tag")}
- disabled={tags.readOnly}
- // Derived per node: the nodes agree on the texts, but each may dress its own
- // tags differently, and that is kept by reading from the node being written to.
- onCommit={(texts) => patchSelectedNodes((node) => ({ tags: applyTagTexts(node.tags, texts) }))}
- />
- </PanelSection>
- </div>
-
- {/* The memo goes without a label of its own: the tab it fills is the label, and the
- editor is the whole of the tab rather than a field within it. */}
- {openedTabs.current.has("memo") && (
+ {/* The tabs are stacked one over the other rather than shown one at a time, so that
+ the panel keeps the height of the tallest of them whichever is on show. */}
+ <div className="mind-map-node-panel-bodies">
<div
role="tabpanel"
- className={clsx("mind-map-node-panel-body mind-map-node-panel-memo-body", activeTabId !== "memo" && "hidden-ext")}
- title={memo === MIXED ? t("mind-map.memos-differ") : undefined}
+ className="mind-map-node-panel-body"
+ aria-hidden={activeTabId !== "format"}
>
- <NodeMemo
- selectionKey={nodes.map((node) => node.id).join(" ")}
- memo={memo !== MIXED ? memo : null}
- readOnly={memo === MIXED}
- onCommit={writeMemo}
- />
+ <PanelSection label={t("mind-map.font-size")}>
+ <SegmentedChoice
+ options={buildFontSizeOptions()}
+ currentValue={fontSize !== MIXED ? fontSize ?? DEFAULT_FONT_SIZE : MIXED_FONT_SIZE}
+ onChange={(fontSize) => patchSelectedNodes({ style: { fontSize } })}
+ />
+ </PanelSection>
+
+ <PanelSection label={t("mind-map.text-color")}>
+ <ColorPicker
+ presets={NODE_COLORS}
+ {...toPickerValue(textColor)}
+ // Mind Elixir only ever assigns the style properties it is given and never
+ // resets the ones it isn't, so clearing has to blank the property explicitly.
+ onChange={(color) => patchSelectedNodes({ style: { color: color ?? "" } })}
+ />
+ </PanelSection>
+
+ <PanelSection label={t("mind-map.background-color")}>
+ <ColorPicker
+ presets={NODE_BACKGROUND_COLORS}
+ {...toPickerValue(backgroundColor)}
+ onChange={(color) => patchSelectedNodes({ style: { background: color ?? "" } })}
+ />
+ </PanelSection>
+
+ <PanelSection label={t("mind-map.branch-color")}>
+ <ColorPicker
+ presets={NODE_COLORS}
+ {...toPickerValue(branchColor)}
+ onChange={(color) => patchSelectedNodes({ branchColor: color ?? "" })}
+ />
+ </PanelSection>
+
+ <PanelSection
+ label={t("mind-map.icons")}
+ title={icons.readOnly ? t("mind-map.icons-differ") : undefined}
+ >
+ <NodeIcons
+ icons={icons.values}
+ readOnly={icons.readOnly}
+ onChange={(icons) => patchSelectedNodes({ icons })}
+ />
+ </PanelSection>
+
+ <PanelSection
+ label={t("mind-map.image")}
+ title={image === MIXED ? t("mind-map.images-differ") : undefined}
+ >
+ <NodeImage
+ hasImage={!!image}
+ indeterminate={image === MIXED}
+ width={imageWidth !== MIXED && imageWidth ? Number(imageWidth) : null}
+ shape={imageShape !== MIXED ? imageShape : null}
+ onShape={(shape) => void shapeImages(shape)}
+ // A node carries one picture, so what is taken in takes the place of what was
+ // there, at the size it comes in at.
+ onPick={(file) => void takeInImage(file)}
+ // Derived per node: the nodes are set to the same width, but each keeps the
+ // proportions of the picture it carries.
+ onResize={(width) => patchSelectedNodes((node) => ({
+ image: node.image && fitNodeImage(node.image, width)
+ }))}
+ onRemove={() => patchSelectedNodes({ image: undefined })}
+ />
+ </PanelSection>
+
+ <PanelSection
+ label={t("mind-map.node-link")}
+ title={link === MIXED ? t("mind-map.links-differ") : undefined}
+ >
+ <NodeLink
+ currentValue={link !== MIXED ? link : null}
+ indeterminate={link === MIXED}
+ // A node carries one link, so what is picked takes the place of what was there.
+ // Clearing blanks the property, Mind Elixir only ever assigning the ones it is
+ // given (see the colors above).
+ onChange={(link) => patchSelectedNodes({ hyperLink: link ?? "" })}
+ />
+ </PanelSection>
+
+ <PanelSection
+ label={t("mind-map.tags")}
+ title={tags.readOnly ? t("mind-map.tags-differ") : undefined}
+ >
+ <ValuesInput
+ labelType="text"
+ values={tags.texts}
+ placeholder={t("mind-map.tags-placeholder")}
+ addButtonText={t("mind-map.add-tag")}
+ removeButtonText={t("mind-map.remove-tag")}
+ disabled={tags.readOnly}
+ // Derived per node: the nodes agree on the texts, but each may dress its own
+ // tags differently, and that is kept by reading from the node being written to.
+ onCommit={(texts) => patchSelectedNodes((node) => ({ tags: applyTagTexts(node.tags, texts) }))}
+ />
+ </PanelSection>
</div>
- )}
+
+ {/* The memo goes without a label of its own: the tab it fills is the label, and the
+ editor is the whole of the tab rather than a field within it. */}
+ {openedTabs.current.has("memo") && (
+ <div
+ role="tabpanel"
+ className="mind-map-node-panel-body mind-map-node-panel-memo-body"
+ aria-hidden={activeTabId !== "memo"}
+ title={memo === MIXED ? t("mind-map.memos-differ") : undefined}
+ >
+ <NodeMemo
+ selectionKey={nodes.map((node) => node.id).join(" ")}
+ memo={memo !== MIXED ? memo : null}
+ readOnly={memo === MIXED}
+ onCommit={writeMemo}
+ />
+ </div>
+ )}
+ </div>
</div>
);
}