Skip to content

Build your personal knowledge base with Trilium Notes

style(maps): clear the mobile foot of what the fingers already do

Elian Doran59aad8fb3bc2
diff --git a/apps/client/src/widgets/collections/geomap/index.css b/apps/client/src/widgets/collections/geomap/index.css
index 0c71a51af3..8e470ee098 100644
--- a/apps/client/src/widgets/collections/geomap/index.css
+++ b/apps/client/src/widgets/collections/geomap/index.css
@@ -63,14 +63,20 @@
position: relative;
}
- /* MapLibre spaces its controls off the edge by margins of its own — only the foot of the map
- carries any (the scale and the attribution). Restated in the shared inset's terms, so they
- stand where everything else over the map stands and follow it if it ever moves. */
+ /* MapLibre spaces its controls off the edge by margins of its own; restated in the shared
+ inset's terms, so they stand where everything else over the map stands and follow it if it
+ ever moves. The foot carries the scale and, on desktop, the attribution; on mobile the
+ attribution stands at the head instead (see map.tsx). */
.maplibregl-ctrl-bottom-left .maplibregl-ctrl,
.maplibregl-ctrl-bottom-right .maplibregl-ctrl {
margin-bottom: var(--geo-map-inset);
margin-inline: var(--geo-map-inset);
}
+
+ .maplibregl-ctrl-top-left .maplibregl-ctrl {
+ margin-top: var(--geo-map-inset);
+ margin-inline: var(--geo-map-inset);
+ }
}
/*
diff --git a/apps/client/src/widgets/collections/geomap/map.init.spec.tsx b/apps/client/src/widgets/collections/geomap/map.init.spec.tsx
index 3e46b02445..3395e57caf 100644
--- a/apps/client/src/widgets/collections/geomap/map.init.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/map.init.spec.tsx
@@ -71,7 +71,8 @@ function buildWorkingMap() {
let removed = false;
return {
- addControl: vi.fn((control: unknown) => { controls.add(control); }),
+ // The corner is recorded too, for the test that asks where the credit was stood.
+ addControl: vi.fn((control: unknown, _corner?: string) => { controls.add(control); }),
removeControl: vi.fn((control: unknown) => {
if (removed) {
throw new TypeError(`can't access property "off", this._map is undefined`);
@@ -168,6 +169,25 @@ describe("Map initialization", () => {
expect(container.querySelector(".map-child")).not.toBeNull();
});
+ it("stands the credit at the foot on desktop, and at the head of a mobile map", () => {
+ MapConstructor.mockImplementation(workingMap);
+
+ renderMap();
+ expect(lastMap?.addControl.mock.calls[0][1]).toBe("bottom-left");
+
+ // On mobile the foot is fully spoken for, so the credit moves to the head's leading
+ // corner instead (see the comment in map.tsx).
+ const host = window as unknown as { glob?: { device?: string } };
+ host.glob = { device: "mobile" };
+ try {
+ render(null, container);
+ renderMap();
+ expect(lastMap?.addControl.mock.calls[0][1]).toBe("top-left");
+ } finally {
+ delete host.glob;
+ }
+ });
+
/**
* The app is served with `Referrer-Policy: no-referrer`, and OpenStreetMap answers a request that
* says nothing of itself with a 403 drawn into the tile — an image reading "Access blocked",
diff --git a/apps/client/src/widgets/collections/geomap/map.tsx b/apps/client/src/widgets/collections/geomap/map.tsx
index 4508fca08f..2ff803fa73 100644
--- a/apps/client/src/widgets/collections/geomap/map.tsx
+++ b/apps/client/src/widgets/collections/geomap/map.tsx
@@ -5,6 +5,7 @@ import { ComponentChildren, createContext, RefObject } from "preact";
import { useEffect, useImperativeHandle, useRef, useState } from "preact/hooks";
import { t } from "../../../services/i18n";
+import { isMobile } from "../../../services/utils";
import { getMeasurementSystem } from "../../../utils/formatters";
import { useElementSize, useSyncedRef, useTriliumOption } from "../../react/hooks";
import NoItems from "../../react/NoItems";
@@ -174,8 +175,10 @@ export default function Map({ coordinates, zoom, layerData, viewportChanged, chi
// The attribution stands at the foot of the map beside its scale, rather than in the corner
// where the zoom buttons now are (see MapToolbar): a bar of buttons is reached for, and it
- // would otherwise sit on top of a line of small print that is itself made of links.
- mapInstance.addControl(new AttributionControl(), "bottom-left");
+ // would otherwise sit on top of a line of small print that is itself made of links. On
+ // mobile the foot is fully spoken for, so it stands at the head instead — in the leading
+ // corner, the trailing one being the detail pane's whenever a marker is open.
+ mapInstance.addControl(new AttributionControl(), isMobile() ? "top-left" : "bottom-left");
// An error MapLibre finds no listener for goes to `console.error` with the stack of the
// fetch that failed, and a tile server answering 403 fails once per tile: a screenful of
diff --git a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx
index bbdd75ecd7..8031cddae2 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx
@@ -127,6 +127,22 @@ describe("MapToolbar", () => {
]);
});
+ it("keeps the zoom steps and the readout off a mobile screen, where the fingers already zoom", () => {
+ const host = window as unknown as { glob?: { device?: string } };
+ host.glob = { device: "mobile" };
+ try {
+ const container = renderToolbar(buildMind());
+
+ // What remains is what a gesture cannot do — see the mobile note in MapToolbar.tsx.
+ expect(buttons(container).map((button) => button.className)).toEqual([
+ expect.stringContaining("bx-current-location"),
+ expect.stringContaining("bx-fullscreen")
+ ]);
+ } finally {
+ delete host.glob;
+ }
+ });
+
it("keeps the way out of focus mode off the bar while there is nothing to leave", () => {
const container = renderToolbar(buildMind());
diff --git a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx
index e1372af538..77336eccd8 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx
@@ -4,6 +4,7 @@ import type { MindElixirInstance } from "mind-elixir";
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
import { t } from "../../../services/i18n";
+import { isMobile } from "../../../services/utils";
import { useFullscreen, useStaticTooltip } from "../../react/hooks";
import OverlayToolbar, { OverlayToolbarButton } from "../../react/OverlayToolbar";
import { centerMapOn, type MapPoint, readMapCenter, stepZoom } from "./viewport";
@@ -25,6 +26,10 @@ interface MapToolbarProps {
* between the steps says the scale the way the image viewer says it — a hundred being the map drawn
* at its own size — and pressed, takes the map back there, as the image viewer's does: unlike a geo
* map, a mind map has a natural size to be reset to.
+ *
+ * On mobile the steps and the readout stay home, as the geo map's steps do: the fingers already
+ * zoom, and a narrow foot has little room. What remains is leaving focus, recentering, and the
+ * screen.
*/
export default function MapToolbar({ mind }: MapToolbarProps) {
const scale = useMapScale(mind);
@@ -75,31 +80,33 @@ export default function MapToolbar({ mind }: MapToolbarProps) {
/>
)}
- <button
- ref={zoomOutRef}
- type="button"
- className="tn-overlay-icon-button bx bx-minus-circle"
- aria-label={t("mind-map.zoom-out")}
- disabled={zoomedOut === null}
- onClick={() => zoomedOut !== null && mind.scale(zoomedOut)}
- />
- <button
- ref={zoomLevelRef}
- type="button"
- className="tn-overlay-text-button mind-map-zoom-level"
- aria-label={t("mind-map.reset-zoom")}
- onClick={() => mind.scale(1)}
- >
- {Math.round(scale * 100)}%
- </button>
- <button
- ref={zoomInRef}
- type="button"
- className="tn-overlay-icon-button bx bx-plus-circle"
- aria-label={t("mind-map.zoom-in")}
- disabled={zoomedIn === null}
- onClick={() => zoomedIn !== null && mind.scale(zoomedIn)}
- />
+ {!isMobile() && <>
+ <button
+ ref={zoomOutRef}
+ type="button"
+ className="tn-overlay-icon-button bx bx-minus-circle"
+ aria-label={t("mind-map.zoom-out")}
+ disabled={zoomedOut === null}
+ onClick={() => zoomedOut !== null && mind.scale(zoomedOut)}
+ />
+ <button
+ ref={zoomLevelRef}
+ type="button"
+ className="tn-overlay-text-button mind-map-zoom-level"
+ aria-label={t("mind-map.reset-zoom")}
+ onClick={() => mind.scale(1)}
+ >
+ {Math.round(scale * 100)}%
+ </button>
+ <button
+ ref={zoomInRef}
+ type="button"
+ className="tn-overlay-icon-button bx bx-plus-circle"
+ aria-label={t("mind-map.zoom-in")}
+ disabled={zoomedIn === null}
+ onClick={() => zoomedIn !== null && mind.scale(zoomedIn)}
+ />
+ </>}
<button
ref={centerRef}
type="button"