[263] Ansichtsleiste: Überlauf-Menü „⋯“ statt verstecktem Scrollen
Gruppen, die nicht passen, wandern nach Priorität (Schrift zuerst, Massstab/Zoom zuletzt) in ein Ausklappmenü am rechten Ende; Neuberechnung per ResizeObserver. Tastatur: Enter/Leertaste, Esc, Pfeile. Test: vitest TopBar.overflow.test.ts, e2e uxReview263.spec.ts.
This commit is contained in:
7 files changed
+329
-38
No files matched your search
@@ -32,6 +32,7 @@ export const de = {
|
||||
"view3d.left.abbr": "L",
|
||||
"view3d.perspective": "Perspektive",
|
||||
"view3d.perspective.hint": "Freie Perspektive (3/4-Blick)",
|
||||
"topbar.more": "Weitere Einstellungen",
|
||||
"topbar.views": "Ansichten",
|
||||
"topbar.views.menu": "Ansicht wählen (Vorne/Hinten/Links/Rechts/Oben)",
|
||||
"topbar.axo": "Axonometrie",
|
||||
|
||||
@@ -31,6 +31,7 @@ export const en: Record<TranslationKey, string> = {
|
||||
"view3d.left.abbr": "L",
|
||||
"view3d.perspective": "Perspective",
|
||||
"view3d.perspective.hint": "Free perspective (3/4 view)",
|
||||
"topbar.more": "More settings",
|
||||
"topbar.views": "Views",
|
||||
"topbar.views.menu": "Pick a view (Front/Back/Left/Right/Top)",
|
||||
"topbar.axo": "Axonometric",
|
||||
|
||||
+46
-10
@@ -182,7 +182,7 @@ body {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
/* Die Leiste selbst scrollt NICHT — nur der mittlere View-Controls-Block
|
||||
(.ribbon-views) scrollt bei schmalen Fenstern. So bleiben Marke, Menü und
|
||||
(.ribbon-views) lagert bei schmalen Fenstern Gruppen ins „⋯“-Menü aus. So bleiben Marke, Menü und
|
||||
die rechte Gruppe (Datei-Aktionen + Projekt) IMMER sichtbar. */
|
||||
overflow: visible;
|
||||
white-space: nowrap;
|
||||
@@ -7730,18 +7730,54 @@ body {
|
||||
gap: 8px;
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
scrollbar-width: none;
|
||||
position: relative;
|
||||
}
|
||||
.ribbon-views::-webkit-scrollbar {
|
||||
/* [263] Gruppen in der Leiste; was nicht passt, steht im „⋯“-Menü (TopBar.tsx, `overflowHidden`) — kein verstecktes Scrollen. */
|
||||
.rv-slot {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
.rv-more {
|
||||
position: relative;
|
||||
flex: 0 0 auto;
|
||||
margin-left: auto;
|
||||
}
|
||||
.rv-more-btn {
|
||||
width: 30px;
|
||||
font-size: 16px;
|
||||
line-height: 1;
|
||||
}
|
||||
.rv-more-panel {
|
||||
position: fixed;
|
||||
z-index: 1090;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
padding: 10px 12px;
|
||||
width: max-content;
|
||||
max-width: calc(100vw - 16px);
|
||||
background: var(--panel-2);
|
||||
color: var(--ink);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
box-shadow: var(--shadow-2, 0 8px 24px rgba(0, 0, 0, 0.25));
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rv-more-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.rv-more-row .rv-slot,
|
||||
.rv-more-row > * {
|
||||
gap: 8px;
|
||||
}
|
||||
.rv-more-panel .tb-sep {
|
||||
display: none;
|
||||
}
|
||||
/* [263] Es gibt rechts noch Bedienelemente ausserhalb des Fensters: Rand ausblenden. */
|
||||
.ribbon-views.has-more {
|
||||
-webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
|
||||
mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
|
||||
}
|
||||
|
||||
/* ── Layout-Blatt im Haupt-Viewport (DOSSIER A3, Phase 2b) ─────────────────────
|
||||
Das Blatt liegt auf einem dunklen „Tisch"; oben eine schlanke Werkzeugleiste,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// [263] Überlauf-Menü der Ansichtsleiste: welche Gruppen wandern bei zu wenig Platz ins „⋯“.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { overflowHidden } from "./TopBar";
|
||||
|
||||
const ids = ["views", "combos", "detail", "zoom", "sketch", "text"];
|
||||
const widths = new Map([
|
||||
["views", 140],
|
||||
["combos", 410],
|
||||
["detail", 290],
|
||||
["zoom", 370],
|
||||
["sketch", 70],
|
||||
["text", 710],
|
||||
]);
|
||||
|
||||
describe("overflowHidden", () => {
|
||||
it("nichts, wenn alles passt", () => {
|
||||
expect(overflowHidden(ids, widths, 2200)).toEqual([]);
|
||||
});
|
||||
it("zuerst Schrift, dann Skizze, dann Kombinationen, dann Detail", () => {
|
||||
expect(overflowHidden(ids, widths, 1478)).toEqual(["text"]);
|
||||
expect(overflowHidden(ids, widths, 1000)).toEqual(["combos", "sketch", "text"]);
|
||||
expect(overflowHidden(ids, widths, 800)).toEqual(["combos", "detail", "sketch", "text"]);
|
||||
});
|
||||
it("Massstab/Zoom bleibt am längsten", () => {
|
||||
expect(overflowHidden(ids, widths, 420)).toEqual(["views", "combos", "detail", "sketch", "text"]);
|
||||
expect(overflowHidden(ids, widths, 10)).toContain("zoom");
|
||||
});
|
||||
});
|
||||
+171
-18
@@ -15,7 +15,7 @@ import { useModalFocus } from "./modalFocus";
|
||||
import { checkForUpdate } from "../update/checkForUpdate";
|
||||
import { getRunningVersion } from "../update/version";
|
||||
import { BUILD_INFO, formatBuildInfo } from "../update/buildInfo";
|
||||
import { memo, useEffect, useRef, useState } from "react";
|
||||
import { memo, useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import { useLiveScale, zoomPercentOf } from "../state/liveScaleStore";
|
||||
import { createPortal } from "react-dom";
|
||||
import { Dropdown } from "./Dropdown";
|
||||
@@ -112,6 +112,26 @@ export interface ComboMenuHandlers {
|
||||
deleteDrawingCombo: (name: string) => void;
|
||||
}
|
||||
|
||||
/** [263] Ansichtsleiste: Reihenfolge, in der Gruppen ins „⋯“-Menü wandern (zuerst Schrift, zuletzt Massstab/Zoom). */
|
||||
const OVERFLOW_ORDER = ["text", "sketch", "shadows", "combos", "detail", "views", "zoom"];
|
||||
const RIBBON_GAP = 8;
|
||||
const MORE_BTN_WIDTH = 30;
|
||||
|
||||
/** Welche Gruppen passen nicht in `avail` px? Rechnet aus den gemerkten Breiten, unwichtigste zuerst. */
|
||||
export function overflowHidden(ids: string[], widths: Map<string, number>, avail: number): string[] {
|
||||
const hide: string[] = [];
|
||||
const total = () => {
|
||||
const vis = ids.filter((i) => !hide.includes(i));
|
||||
const sum = vis.reduce((a, i) => a + (widths.get(i) ?? 0), 0) + RIBBON_GAP * Math.max(0, vis.length - 1);
|
||||
return sum + (hide.length > 0 ? MORE_BTN_WIDTH + RIBBON_GAP : 0);
|
||||
};
|
||||
for (const id of OVERFLOW_ORDER) {
|
||||
if (total() <= avail) break;
|
||||
if (ids.includes(id)) hide.push(id);
|
||||
}
|
||||
return ids.filter((i) => hide.includes(i));
|
||||
}
|
||||
|
||||
/** Kleiner vertikaler Trenner zwischen Gruppen. */
|
||||
function Sep() {
|
||||
return <span className="tb-sep" aria-hidden="true" />;
|
||||
@@ -1118,26 +1138,89 @@ export const ViewRibbonTab = memo(function ViewRibbonTab({
|
||||
{ value: "__custom__", label: t("topbar.scale.custom") },
|
||||
];
|
||||
|
||||
// [263] Die Ansichts-Leiste scrollt ohne sichtbare Leiste: bei schmalem Fenster (1280 px) liegen Massstab,
|
||||
// Zoom und Schrift rechts ausserhalb. Ein Ausblenden am rechten Rand (Klasse `has-more`) zeigt, dass es weitergeht.
|
||||
// [263] Überlauf-Menü „⋯“: Passt die Leiste nicht, wandern Gruppen (nach Priorität, unwichtigste zuerst) in ein
|
||||
// Ausklappmenü am rechten Ende; Massstab/Zoom bleiben am längsten sichtbar. Die Breiten werden gemerkt, solange eine
|
||||
// Gruppe in der Leiste steht; die Auswahl rechnet daraus bei jeder Grössenänderung neu (ResizeObserver).
|
||||
const ribbonRef = useRef<HTMLDivElement | null>(null);
|
||||
useEffect(() => {
|
||||
const widthsRef = useRef(new Map<string, number>());
|
||||
const [hidden, setHidden] = useState<string[]>([]);
|
||||
const [moreOpen, setMoreOpen] = useState(false);
|
||||
const moreBtnRef = useRef<HTMLButtonElement | null>(null);
|
||||
const morePanelRef = useRef<HTMLDivElement | null>(null);
|
||||
const [morePos, setMorePos] = useState({ top: 0, right: 0 });
|
||||
const slotIds = ["views", "combos", "detail", "zoom"];
|
||||
if (shadowsAvailable) slotIds.push("shadows");
|
||||
if (sketchAvailable && onSketch) slotIds.push("sketch");
|
||||
slotIds.push("text");
|
||||
const slotKey = slotIds.join(",");
|
||||
useLayoutEffect(() => {
|
||||
const el = ribbonRef.current;
|
||||
if (!el) return;
|
||||
const update = () => el.classList.toggle("has-more", el.scrollWidth - el.clientWidth - el.scrollLeft > 2);
|
||||
const update = () => {
|
||||
for (const c of Array.from(el.querySelectorAll<HTMLElement>(":scope > [data-slot]"))) {
|
||||
const w = c.getBoundingClientRect().width;
|
||||
if (w > 0) widthsRef.current.set(c.dataset.slot!, w);
|
||||
}
|
||||
const next = overflowHidden(slotKey.split(","), widthsRef.current, el.clientWidth);
|
||||
setHidden((h) => (h.length === next.length && h.every((x, i) => x === next[i]) ? h : next));
|
||||
};
|
||||
update();
|
||||
el.addEventListener("scroll", update, { passive: true });
|
||||
const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(update) : null;
|
||||
ro?.observe(el);
|
||||
for (const c of Array.from(el.children)) ro?.observe(c);
|
||||
return () => {
|
||||
el.removeEventListener("scroll", update);
|
||||
ro?.disconnect();
|
||||
};
|
||||
return () => ro?.disconnect();
|
||||
});
|
||||
useEffect(() => {
|
||||
if (hidden.length === 0) setMoreOpen(false);
|
||||
}, [hidden.length]);
|
||||
useEffect(() => {
|
||||
if (!moreOpen) return;
|
||||
const r = moreBtnRef.current?.getBoundingClientRect();
|
||||
if (r) setMorePos({ top: r.bottom + 6, right: Math.max(8, window.innerWidth - r.right) });
|
||||
morePanelRef.current?.querySelector<HTMLElement>("button:not(:disabled), select, input:not(:disabled)")?.focus({ preventScroll: true });
|
||||
const onDown = (e: PointerEvent) => {
|
||||
const tgt = e.target as Element | null;
|
||||
// Untermenüs (Dropdown) und Dialoge liegen im Body: nicht als Aussenklick werten.
|
||||
if (!tgt || morePanelRef.current?.contains(tgt) || moreBtnRef.current?.contains(tgt) || tgt.closest(".tb-dd-menu, .ctx-menu, [role=dialog]")) return;
|
||||
setMoreOpen(false);
|
||||
};
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key !== "Escape" || e.defaultPrevented) return;
|
||||
if (document.querySelector(".tb-dd-menu, [role=dialog]")) return; // zuerst das Untermenü bzw. der Dialog
|
||||
e.preventDefault();
|
||||
setMoreOpen(false);
|
||||
moreBtnRef.current?.focus({ preventScroll: true });
|
||||
};
|
||||
const onResize = () => setMoreOpen(false);
|
||||
window.addEventListener("pointerdown", onDown, true);
|
||||
window.addEventListener("keydown", onKey);
|
||||
window.addEventListener("resize", onResize);
|
||||
return () => {
|
||||
window.removeEventListener("pointerdown", onDown, true);
|
||||
window.removeEventListener("keydown", onKey);
|
||||
window.removeEventListener("resize", onResize);
|
||||
};
|
||||
}, [moreOpen]);
|
||||
const onMoreKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return;
|
||||
const tgt = e.target as HTMLElement;
|
||||
if (tgt.tagName === "INPUT" || tgt.tagName === "SELECT" || tgt.tagName === "TEXTAREA") return;
|
||||
const items = Array.from(morePanelRef.current?.querySelectorAll<HTMLElement>("button:not(:disabled), select, input:not(:disabled)") ?? []);
|
||||
if (items.length === 0) return;
|
||||
e.preventDefault();
|
||||
const i = items.indexOf(document.activeElement as HTMLElement);
|
||||
const to = e.key === "ArrowDown" ? (i + 1) % items.length : (i - 1 + items.length) % items.length;
|
||||
items[to]?.focus({ preventScroll: true });
|
||||
};
|
||||
// Gruppe in der Leiste oder (wenn verdrängt) im Menü.
|
||||
const bar: Record<string, React.ReactNode> = {};
|
||||
const menu: Record<string, React.ReactNode> = {};
|
||||
const put = (id: string, node: React.ReactNode) => {
|
||||
(hidden.includes(id) ? menu : bar)[id] = node;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="ribbon-views" ref={ribbonRef}>
|
||||
put("views", (
|
||||
<>
|
||||
{/* Reihenfolge: Grundriss · Ansichten · Iso · Axo — ohne Trennstriche
|
||||
(eine zusammenhängende Symbol-Zeile, Nutzer-Wunsch). */}
|
||||
<span className="tb-viewtoggle" role="group" aria-label={t("topbar.viewGroup")}>
|
||||
@@ -1194,7 +1277,10 @@ export const ViewRibbonTab = memo(function ViewRibbonTab({
|
||||
</button>
|
||||
</span>
|
||||
<Sep />
|
||||
|
||||
</>
|
||||
));
|
||||
put("combos", (
|
||||
<>
|
||||
{/* Sichtbarkeits-Kombinationen (Ebenen-/Zeichnungskombinationen). */}
|
||||
<div className="tb-group tb-stack" role="group" aria-label={t("combo.layers.title")}>
|
||||
<label className="tb-field tb-field-row">
|
||||
@@ -1221,7 +1307,10 @@ export const ViewRibbonTab = memo(function ViewRibbonTab({
|
||||
</label>
|
||||
</div>
|
||||
<Sep />
|
||||
|
||||
</>
|
||||
));
|
||||
put("detail", (
|
||||
<>
|
||||
{/* Detailgrad (grob/mittel/fein) + Darstellungsart übereinander gestapelt
|
||||
(Nutzer-Wunsch) — gleiches Stapel-Muster wie die Kombinationen. */}
|
||||
<div className="tb-group tb-stack" role="group" aria-label={t("topbar.detailGroup")}>
|
||||
@@ -1268,7 +1357,10 @@ export const ViewRibbonTab = memo(function ViewRibbonTab({
|
||||
)}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</>
|
||||
));
|
||||
put("zoom", (
|
||||
<>
|
||||
{/* Massstab/Zoom + Text-Formatierung OHNE Trennstriche, gleich gross wie
|
||||
die Dropdowns (Mockup). */}
|
||||
<div className="tb-group tb-zoomcluster" role="group" aria-label={t("topbar.scaleGroup")}>
|
||||
@@ -1312,7 +1404,11 @@ export const ViewRibbonTab = memo(function ViewRibbonTab({
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</>
|
||||
));
|
||||
if (shadowsAvailable)
|
||||
put("shadows", (
|
||||
<>
|
||||
{/* Schatten ein/aus — NUR für eine aktive Ansicht (kind "elevation").
|
||||
Schreibt DrawingLevel.shadows; der Ansichts-Generator (toElevation)
|
||||
zeichnet dann den 45°-Schlagschatten auskragender Bauteile. */}
|
||||
@@ -1331,7 +1427,11 @@ export const ViewRibbonTab = memo(function ViewRibbonTab({
|
||||
<Sep />
|
||||
</>
|
||||
)}
|
||||
|
||||
</>
|
||||
));
|
||||
if (sketchAvailable && onSketch)
|
||||
put("sketch", (
|
||||
<>
|
||||
{sketchAvailable && onSketch && (
|
||||
<>
|
||||
<div className="tb-group" role="group" aria-label={t("view.sketch")}>
|
||||
@@ -1348,11 +1448,64 @@ export const ViewRibbonTab = memo(function ViewRibbonTab({
|
||||
<Sep />
|
||||
</>
|
||||
)}
|
||||
|
||||
</>
|
||||
));
|
||||
put("text", (
|
||||
<>
|
||||
{/* Text-/Font-Formatierung auf DERSELBEN Leiste (Nutzer-Wunsch: Text und
|
||||
Ansichten zusammen) — Stil/Schrift/Grösse + B/I/U · L/C/R + Zeilenhöhe,
|
||||
formatiert das aktuelle Text-Ziel (Raumstempel) live. */}
|
||||
<TextGroup textTarget={textTarget} textStyles={textStyles} />
|
||||
</>
|
||||
));
|
||||
const order = slotIds;
|
||||
|
||||
return (
|
||||
<div className="ribbon-views" ref={ribbonRef}>
|
||||
{order.map((id) =>
|
||||
bar[id] ? (
|
||||
<div key={id} className="rv-slot" data-slot={id}>
|
||||
{bar[id]}
|
||||
</div>
|
||||
) : null,
|
||||
)}
|
||||
{hidden.length > 0 && (
|
||||
<div className="rv-more">
|
||||
<button
|
||||
ref={moreBtnRef}
|
||||
type="button"
|
||||
className={`tb-vt-btn rv-more-btn${moreOpen ? " active" : ""}`}
|
||||
title={t("topbar.more")}
|
||||
aria-label={t("topbar.more")}
|
||||
aria-haspopup="true"
|
||||
aria-expanded={moreOpen}
|
||||
data-testid="ribbon-more"
|
||||
onClick={() => setMoreOpen((o) => !o)}
|
||||
>
|
||||
<span aria-hidden="true">⋯</span>
|
||||
</button>
|
||||
{moreOpen && createPortal(
|
||||
<div
|
||||
ref={morePanelRef}
|
||||
className="rv-more-panel"
|
||||
style={{ top: morePos.top, right: morePos.right }}
|
||||
role="group"
|
||||
aria-label={t("topbar.more")}
|
||||
data-testid="ribbon-more-panel"
|
||||
onKeyDown={onMoreKeyDown}
|
||||
>
|
||||
{order.map((id) =>
|
||||
menu[id] ? (
|
||||
<div key={id} className="rv-more-row" data-slot={id}>
|
||||
{menu[id]}
|
||||
</div>
|
||||
) : null,
|
||||
)}
|
||||
</div>,
|
||||
document.body,
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{scalePromptOpen && (
|
||||
<PromptDialog
|
||||
title={t("topbar.scale.custom")}
|
||||
|
||||
Reference in new issue
Block a user