Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8786 fix(views): show the full property label when it is cut off (#10138)

Jiayuan Zhang8886a0b4d88a
diff --git a/packages/views/layout/object-page.test.tsx b/packages/views/layout/object-page.test.tsx
index 68569c07f4..edcc338b97 100644
--- a/packages/views/layout/object-page.test.tsx
+++ b/packages/views/layout/object-page.test.tsx
@@ -1,6 +1,7 @@
-import { screen, within } from "@testing-library/react";
+import { act, fireEvent, screen, within } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
import { Pencil } from "@multica/ui/icons";
-import { describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { NavigationProvider, type NavigationAdapter } from "../navigation";
import { renderWithI18n } from "../test/i18n";
import {
@@ -73,3 +74,109 @@ describe("ObjectPage", () => {
expect(screen.getByText("MacBook Pro")).toBeInTheDocument();
});
});
+
+describe("ObjectProperty label", () => {
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ const tooltip = () => document.querySelector("[data-slot=tooltip-content]");
+
+ function hover(el: HTMLElement) {
+ vi.useFakeTimers();
+ fireEvent.pointerEnter(el, { pointerType: "mouse" });
+ act(() => {
+ vi.advanceTimersByTime(550);
+ });
+ }
+
+ // jsdom does not lay out text: model a translation wider than the label column.
+ function setWidths(el: HTMLElement, scrollWidth: number) {
+ el.style.overflowX = "hidden";
+ Object.defineProperties(el, {
+ scrollWidth: { configurable: true, value: scrollWidth },
+ clientWidth: { configurable: true, value: 80 },
+ });
+ }
+
+ it("shows the full label on hover when it is cut off", () => {
+ renderWithI18n(<ObjectProperty label="Identifiant du daemon">a1b2c3</ObjectProperty>);
+ const label = screen.getByText("Identifiant du daemon");
+ setWidths(label, 124);
+ hover(label);
+ expect(tooltip()).toHaveTextContent("Identifiant du daemon");
+ });
+
+ it("stays quiet when the label fits", () => {
+ renderWithI18n(<ObjectProperty label="Runtime">MacBook Pro</ObjectProperty>);
+ const label = screen.getByText("Runtime");
+ setWidths(label, 48);
+ hover(label);
+ expect(tooltip()).toBeNull();
+ });
+
+ describe("keyboard", () => {
+ // The label re-measures when it resizes; jsdom never fires that, so the
+ // test does once it has given the labels their widths.
+ let resized: (() => void)[] = [];
+ beforeEach(() => {
+ resized = [];
+ vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ constructor(private callback: () => void) {}
+ observe() {
+ resized.push(() => this.callback());
+ }
+ disconnect() {}
+ },
+ );
+ });
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ function renderPanel() {
+ renderWithI18n(
+ <>
+ <button type="button">Before</button>
+ <ObjectProperty label="Ejecuciones (7 d)">
+ <button type="button">Runs</button>
+ </ObjectProperty>
+ <ObjectProperty label="Estado">
+ <button type="button">Status</button>
+ </ObjectProperty>
+ </>,
+ );
+ setWidths(screen.getByText("Ejecuciones (7 d)"), 98);
+ setWidths(screen.getByText("Estado"), 38);
+ act(() => resized.forEach((fire) => fire()));
+ }
+
+ it("reaches a cut-off label with Tab and shows its full text until focus leaves", async () => {
+ const user = userEvent.setup();
+ renderPanel();
+ const label = screen.getByText("Ejecuciones (7 d)");
+ screen.getByRole("button", { name: "Before" }).focus();
+
+ await user.tab();
+ expect(label).toHaveFocus();
+ expect(tooltip()).toHaveTextContent("Ejecuciones (7 d)");
+
+ await user.tab();
+ expect(screen.getByRole("button", { name: "Runs" })).toHaveFocus();
+ expect(tooltip()).toBeNull();
+ });
+
+ it("keeps a label that fits out of the tab order", async () => {
+ const user = userEvent.setup();
+ renderPanel();
+ screen.getByRole("button", { name: "Runs" }).focus();
+
+ await user.tab();
+ expect(screen.getByRole("button", { name: "Status" })).toHaveFocus();
+ expect(screen.getByText("Estado")).not.toHaveAttribute("tabindex");
+ expect(tooltip()).toBeNull();
+ });
+ });
+});
diff --git a/packages/views/layout/object-page.tsx b/packages/views/layout/object-page.tsx
index a03a1377e0..ff24e0ea03 100644
--- a/packages/views/layout/object-page.tsx
+++ b/packages/views/layout/object-page.tsx
@@ -8,11 +8,13 @@ import {
type ComponentProps,
type ReactNode,
type Ref,
+ type RefObject,
} from "react";
import { useDefaultLayout, usePanelRef } from "react-resizable-panels";
import { ChevronRight, PanelRight, type IconComponent } from "@multica/ui/icons";
import { Button } from "@multica/ui/components/ui/button";
import { IconButton } from "@multica/ui/components/common/icon-button";
+import { isContentTruncated, TruncatedTooltip } from "@multica/ui/components/common/truncated-tooltip";
import {
ResizableHandle,
ResizablePanel,
@@ -360,11 +362,45 @@ export function ObjectPanelSection({
);
}
+/** Whether `ref`'s content is cut off, re-checked when it resizes or web fonts finish loading. */
+function useIsTruncated(ref: RefObject<HTMLElement | null>, content: ReactNode) {
+ const [truncated, setTruncated] = useState(false);
+ useEffect(() => {
+ const el = ref.current;
+ if (!el) return;
+ let active = true;
+ const check = () => {
+ if (active) setTruncated(isContentTruncated(el));
+ };
+ check();
+ void document.fonts?.ready.then(check);
+ const observer = new ResizeObserver(check);
+ observer.observe(el);
+ return () => {
+ active = false;
+ observer.disconnect();
+ };
+ }, [ref, content]);
+ return truncated;
+}
+
/** One label and value in the properties panel; the value may be a picker. */
export function ObjectProperty({ label, children }: { label: ReactNode; children: ReactNode }) {
+ const labelRef = useRef<HTMLSpanElement>(null);
+ // A cut-off label takes keyboard focus so its tooltip can show the full text;
+ // a label that fits stays out of the tab order.
+ const truncated = useIsTruncated(labelRef, label);
return (
<div className="-mx-2 flex min-h-8 items-center gap-2 rounded-md px-2 transition-colors hover:bg-accent/50">
- <span className="w-20 shrink-0 truncate text-caption text-muted-foreground">{label}</span>
+ <TruncatedTooltip content={label}>
+ <span
+ ref={labelRef}
+ tabIndex={truncated ? 0 : undefined}
+ className="w-20 shrink-0 truncate rounded-sm text-caption text-muted-foreground outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
+ >
+ {label}
+ </span>
+ </TruncatedTooltip>
<div className="flex min-w-0 flex-1 items-center gap-1.5 truncate text-caption">{children}</div>
</div>
);
diff --git a/packages/views/locales/fr/runtimes.json b/packages/views/locales/fr/runtimes.json
index d7660a4a1d..4983a20922 100644
--- a/packages/views/locales/fr/runtimes.json
+++ b/packages/views/locales/fr/runtimes.json
@@ -160,7 +160,7 @@
"fact_device": "Appareil",
"fact_runtime": "Runtime",
"fact_daemon_cli": "CLI du daemon",
- "fact_daemon_id": "Identifiant du daemon",
+ "fact_daemon_id": "ID du daemon",
"usage_title": "Consommation",
"no_agents": "Aucun agent n'est encore associé à ce runtime.",
"diagnostics_cli": "CLI",