Skip to content

Commit 421a88a

Browse files
committed
fix(ui): hug auto widget cards to content and compact board chrome into a top-left pill
1 parent 5aef172 commit 421a88a

6 files changed

Lines changed: 195 additions & 49 deletions

File tree

‎ui/src/components/board/board-view-sizing.test.ts‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { afterEach, describe, expect, it, vi } from "vitest";
2-
import { effectiveBoardWidgetRows } from "../../lib/board/grid.ts";
2+
import {
3+
boardChromeRowPx,
4+
effectiveBoardWidgetRows,
5+
exactBoardWidgetHeightPx,
6+
} from "../../lib/board/grid.ts";
37
// Side-effect import: test-support only type-imports the component, so the
48
// custom element must be registered here for mount() to render anything.
59
import "./board-view.ts";
@@ -29,6 +33,46 @@ describe("board widget sizing", () => {
2933
expect(effectiveBoardWidgetRows(card, 150, 0)).toBe(3);
3034
});
3135

36+
it("hugs auto cards to their exact content height inside the quantized cell", () => {
37+
const card = boardWidget({ sizeH: 6 });
38+
// Card inset adds 12px per edge; frameless/full-bleed report bare content.
39+
expect(exactBoardWidgetHeightPx(card, 300)).toBe(324);
40+
expect(exactBoardWidgetHeightPx({ ...card, presentation: "frameless" }, 300)).toBe(300);
41+
// Short content hugs below the 2-row cell minimum: the cell keeps its
42+
// minimum span, only the card shrinks.
43+
expect(exactBoardWidgetHeightPx(card, 60)).toBe(84);
44+
// At the 20-row cap the card fills the cell exactly and the body clips.
45+
expect(exactBoardWidgetHeightPx(card, 10_000)).toBe(20 * 56 + 19 * 12);
46+
// Coarse-pointer layouts keep the 38px bar in flow, joining the height.
47+
expect(exactBoardWidgetHeightPx(card, 300, 38)).toBe(362);
48+
expect(exactBoardWidgetHeightPx({ ...card, heightMode: "fixed" }, 300)).toBeUndefined();
49+
expect(exactBoardWidgetHeightPx(card, undefined)).toBeUndefined();
50+
expect(exactBoardWidgetHeightPx({ ...card, contentKind: "mcp-app" }, 300)).toBeUndefined();
51+
});
52+
53+
it("pins the exact reported height on the card and re-fills while dragging", async () => {
54+
const view = await mount();
55+
const cell = view.querySelector("openclaw-board-widget-cell");
56+
const frame = cell?.querySelector("iframe");
57+
window.dispatchEvent(
58+
new MessageEvent("message", {
59+
source: frame?.contentWindow ?? null,
60+
data: { type: "openclaw:widget-size", height: 300 },
61+
}),
62+
);
63+
const widget = boardWidget();
64+
const expected = exactBoardWidgetHeightPx(widget, 300, boardChromeRowPx());
65+
const section = () => cell?.querySelector<HTMLElement>(".board-widget");
66+
await vi.waitFor(() => {
67+
expect(section()?.getAttribute("style")).toContain(`height: ${expected}px`);
68+
expect(section()?.getAttribute("style")).toContain("align-self: start");
69+
});
70+
// Gestures manipulate the quantized cell, so the card fills it again.
71+
Reflect.set(cell ?? {}, "dragging", true);
72+
await cell?.updateComplete;
73+
expect(section()?.getAttribute("style")).not.toContain("align-self");
74+
});
75+
3276
it("pins preset resizing and toggles height mode from the menu", async () => {
3377
const applyOps = vi.fn(async () => undefined);
3478
const view = await mount({ callbacks: callbacks({ applyOps }) });

‎ui/src/components/board/board-view.browser.test.ts‎

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,49 @@ describe.skipIf(!hasBrowserLayout)("openclaw-board-view browser layout", () => {
133133

134134
widget!.focus();
135135
expect(getComputedStyle(bar!).visibility).toBe("visible");
136-
// The revealed strip must not steal clicks from widget content under it;
137-
// only real controls (drag handle, kebab) stay interactive.
138-
expect(getComputedStyle(bar!).pointerEvents).toBe("none");
139-
const handle = bar!.querySelector<HTMLElement>(".board-widget__drag-handle");
140-
const trigger = bar!.querySelector<HTMLElement>(".board-widget__menu-trigger");
141-
expect(getComputedStyle(handle!).pointerEvents).toBe("auto");
142-
expect(getComputedStyle(trigger!).pointerEvents).toBe("auto");
136+
// Chrome is a compact top-left pill, not a full-width strip: it must not
137+
// stretch across the card, so widget-owned top-right actions stay clear.
138+
const barBounds = bar!.getBoundingClientRect();
139+
const widgetBounds = widget!.getBoundingClientRect();
140+
expect(barBounds.width).toBeLessThan(widgetBounds.width * 0.75);
141+
expect(barBounds.left - widgetBounds.left).toBeLessThan(widgetBounds.right - barBounds.right);
143142

144143
sink.focus();
145144
expect(widget!.matches(":focus-within")).toBe(false);
146145
await vi.waitFor(() => expectChromeHidden(widget!, bar!));
147146
});
148147

148+
it("reserves the top-right action corner even for narrow long-titled widgets", async () => {
149+
const view = await mount();
150+
view.snapshot = {
151+
...structuredClone(source),
152+
widgets: [
153+
{
154+
...source.widgets[0]!,
155+
sizeW: 6,
156+
title: "An extremely long widget title that wants the whole bar",
157+
grantState: "granted",
158+
},
159+
],
160+
};
161+
await view.updateComplete;
162+
const cell = view.querySelector("openclaw-board-widget-cell");
163+
await cell?.updateComplete;
164+
const widget = view.querySelector<HTMLElement>('[data-test-id="board-widget"]');
165+
const bar = widget!.querySelector<HTMLElement>(".board-widget__bar");
166+
widget!.focus();
167+
expect(getComputedStyle(bar!).visibility).toBe("visible");
168+
// The interactive pill reserves a widget-owned right-hand region and none
169+
// of its children may overflow the capped box into that corner.
170+
const widgetBounds = widget!.getBoundingClientRect();
171+
expect(widgetBounds.right - bar!.getBoundingClientRect().right).toBeGreaterThanOrEqual(88);
172+
for (const child of bar!.children) {
173+
expect(child.getBoundingClientRect().right).toBeLessThanOrEqual(
174+
bar!.getBoundingClientRect().right + 1,
175+
);
176+
}
177+
});
178+
149179
it("keeps widget chrome visible while its menu is open", async () => {
150180
const view = await mount();
151181
const sink = focusSink();
@@ -272,11 +302,9 @@ describe.skipIf(!hasBrowserLayout)("openclaw-board-view browser layout", () => {
272302
data: { type: "openclaw:widget-size", height: 300 },
273303
}),
274304
);
275-
await vi.waitFor(() =>
276-
expect(Math.round(first.getBoundingClientRect().height)).toBe(
277-
BOARD_GRID_ROW_HEIGHT * 5 + BOARD_GRID_GAP * 4,
278-
),
279-
);
305+
// The card hugs its exact content height (300px + 2x12px card inset); the
306+
// ceil-to-row slack stays outside the card as grid background.
307+
await vi.waitFor(() => expect(Math.round(first.getBoundingClientRect().height)).toBe(324));
280308
expect(second.getBoundingClientRect().top).toBeGreaterThan(secondTopBefore);
281309

282310
const cardBody = first.querySelector<HTMLElement>(".board-widget__body");

‎ui/src/components/board/board-view.ts‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,10 @@ class OpenClawBoardView extends OpenClawLightDomElement {
259259
if (!widget || widget.contentKind !== "html") {
260260
return;
261261
}
262-
const chromeRowPx = boardChromeRowPx();
263-
const previousRows = effectiveBoardWidgetRows(
264-
widget,
265-
this.contentHeights.get(name),
266-
chromeRowPx,
267-
);
268-
this.contentHeights.set(name, height);
269-
if (effectiveBoardWidgetRows(widget, height, chromeRowPx) !== previousRows) {
262+
// Any pixel change matters: the cell renders the exact reported height,
263+
// not just the quantized row span.
264+
if (this.contentHeights.get(name) !== height) {
265+
this.contentHeights.set(name, height);
270266
this.requestUpdate();
271267
}
272268
},
@@ -654,6 +650,7 @@ class OpenClawBoardView extends OpenClawLightDomElement {
654650
<openclaw-board-widget-cell
655651
.widget=${widget}
656652
.rect=${rect}
653+
.contentHeightPx=${this.contentHeights.get(widget.name)}
657654
.tabs=${tabs}
658655
.sessionKey=${sessionKey}
659656
.widgetFrameUrl=${this.widgetFrameUrl}

‎ui/src/components/board/board-widget-cell.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { applicationContext, type ApplicationContext } from "../../app/context.t
55
import { ensureCustomElementDefined } from "../../app/lazy-custom-element.ts";
66
import { t } from "../../i18n/index.ts";
77
import type { BoardGridDirection, BoardGridRect } from "../../lib/board/grid.ts";
8-
import { toCssPlacement } from "../../lib/board/grid.ts";
8+
import {
9+
boardChromeRowPx,
10+
exactBoardWidgetHeightPx,
11+
toCssPlacement,
12+
} from "../../lib/board/grid.ts";
913
import type { BoardWidgetAppViewState } from "../../lib/board/provider.ts";
1014
import type { BoardTab } from "../../lib/board/types.ts";
1115
import type {
@@ -64,6 +68,7 @@ class OpenClawBoardWidgetCell extends OpenClawLightDomElement {
6468

6569
@property({ attribute: false }) widget?: BoardViewWidget;
6670
@property({ attribute: false }) rect?: BoardGridRect;
71+
@property({ attribute: false }) contentHeightPx?: number;
6772
@property({ attribute: false }) tabs: readonly BoardTab[] = [];
6873
@property({ attribute: false }) sessionKey = "";
6974
@property({ attribute: false }) widgetFrameUrl?: BoardWidgetFrameUrl;
@@ -390,10 +395,17 @@ class OpenClawBoardWidgetCell extends OpenClawLightDomElement {
390395
bodyScrollable || widget.contentKind === "mcp-app" || widget.contentKind === "plugin";
391396
const presentation =
392397
widget.contentKind === "html" ? (widget.presentation ?? "card") : undefined;
398+
// While a move/resize gesture runs, the card fills its (preview) cell so
399+
// the user manipulates the quantized rect they will actually commit.
400+
const exactHeightPx = this.dragging
401+
? undefined
402+
: exactBoardWidgetHeightPx(widget, this.contentHeightPx, boardChromeRowPx());
403+
const exactHeightStyle =
404+
exactHeightPx === undefined ? "" : ` height: ${exactHeightPx}px; align-self: start;`;
393405
return html`
394406
<section
395407
class=${`board-widget ${this.dragging ? "board-widget--dragging" : ""} ${presentation ? `board-widget--${presentation}` : ""}`}
396-
style=${toCssPlacement(rect)}
408+
style=${`${toCssPlacement(rect)}${exactHeightStyle}`}
397409
role="listitem"
398410
tabindex=${this.focusTabIndex}
399411
aria-posinset=${this.positionInSet}

‎ui/src/lib/board/grid.ts‎

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ export function boardChromeRowPx(): number {
216216
: 0;
217217
}
218218

219-
export function effectiveBoardWidgetRows(
219+
function autoBoardWidgetHeightPx(
220220
widget: BoardWidgetSizingInput,
221221
contentHeightPx: number | undefined,
222-
chromeRowPx = 0,
223-
): number {
222+
chromeRowPx: number,
223+
): number | undefined {
224224
// Absent heightMode means auto BY DESIGN, including widgets pinned before
225225
// the contract existed: retroactive content-fitting is the product goal, and
226226
// one menu click re-pins. Only an explicit "fixed" preserves stored height.
@@ -231,18 +231,57 @@ export function effectiveBoardWidgetRows(
231231
!Number.isFinite(contentHeightPx) ||
232232
contentHeightPx <= 0
233233
) {
234-
return widget.sizeH;
234+
return undefined;
235235
}
236-
const requiredHeight =
236+
return (
237237
contentHeightPx +
238238
chromeRowPx +
239-
((widget.presentation ?? "card") === "card" ? BOARD_WIDGET_FRAME_INSET * 2 : 0);
239+
((widget.presentation ?? "card") === "card" ? BOARD_WIDGET_FRAME_INSET * 2 : 0)
240+
);
241+
}
242+
243+
function boardRowSpanPx(rows: number): number {
244+
return rows * BOARD_GRID_ROW_HEIGHT + (rows - 1) * BOARD_GRID_GAP;
245+
}
246+
247+
export function effectiveBoardWidgetRows(
248+
widget: BoardWidgetSizingInput,
249+
contentHeightPx: number | undefined,
250+
chromeRowPx = 0,
251+
): number {
252+
const requiredHeight = autoBoardWidgetHeightPx(widget, contentHeightPx, chromeRowPx);
253+
if (requiredHeight === undefined) {
254+
return widget.sizeH;
255+
}
240256
const rows = Math.ceil(
241257
(requiredHeight + BOARD_GRID_GAP) / (BOARD_GRID_ROW_HEIGHT + BOARD_GRID_GAP),
242258
);
243259
return Math.min(BOARD_WIDGET_AUTO_MAX_ROWS, Math.max(BOARD_WIDGET_AUTO_MIN_ROWS, rows));
244260
}
245261

262+
/**
263+
* Exact card height for auto-sized HTML widgets. The grid cell stays quantized
264+
* to rows (`effectiveBoardWidgetRows`), but the card hugs its content so the
265+
* ceil-to-row slack lands outside the card as background spacing instead of
266+
* dead space inside it. Undefined means "fill the cell" (fixed/non-HTML).
267+
*/
268+
export function exactBoardWidgetHeightPx(
269+
widget: BoardWidgetSizingInput,
270+
contentHeightPx: number | undefined,
271+
chromeRowPx = 0,
272+
): number | undefined {
273+
const requiredHeight = autoBoardWidgetHeightPx(widget, contentHeightPx, chromeRowPx);
274+
if (requiredHeight === undefined) {
275+
return undefined;
276+
}
277+
// Never exceed the quantized cell: at the row cap the content is taller than
278+
// the cell, so the card fills the cell and the body scrolls/clips as before.
279+
return Math.min(
280+
requiredHeight,
281+
boardRowSpanPx(effectiveBoardWidgetRows(widget, contentHeightPx, chromeRowPx)),
282+
);
283+
}
284+
246285
/** Structural sizing inputs so pure grid math stays free of view-type imports. */
247286
type BoardWidgetSizingInput = {
248287
contentKind: string;

‎ui/src/styles/board.css‎

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -748,54 +748,80 @@ openclaw-workboard-mini-widget {
748748
grid-template-rows: minmax(0, 1fr);
749749
}
750750

751+
/* Chrome is a compact top-left pill, not a full-width strip: widgets put
752+
their own actions top-right, so that corner must stay visible and
753+
clickable even while host chrome is revealed. The 30px pill height is
754+
overlay-only; coarse pointers keep the base 38px in-flow grid row that
755+
BOARD_WIDGET_TOUCH_BAR_PX mirrors. */
751756
.board-widget__bar {
752757
backdrop-filter: blur(6px);
753758
background: color-mix(in srgb, var(--board-surface) 92%, transparent);
754-
border-radius: 11px 11px 0 0;
755-
height: 38px;
756-
left: 0;
759+
border: 1px solid var(--board-line);
760+
border-radius: 999px;
761+
box-shadow: 0 4px 14px rgb(0 0 0 / 18%);
762+
height: 30px;
763+
left: 7px;
764+
/* Reserve a widget-owned top-right action region: the interactive pill may
765+
never stretch across the card, or it re-intercepts the exact corner this
766+
chrome exists to keep clickable. The 88px floor keeps the drag handle and
767+
menu usable on very narrow widgets, trading reservation width there. */
768+
max-width: max(88px, calc(100% - 96px));
757769
opacity: 0;
770+
padding: 0 5px;
758771
position: absolute;
759-
right: 0;
760-
top: 0;
772+
top: 7px;
761773
transition:
762-
opacity 120ms ease,
763-
visibility 0s linear 120ms;
774+
opacity 100ms ease,
775+
visibility 0s linear 100ms;
764776
visibility: hidden;
765777
z-index: 5;
766-
/* The overlay strip must not steal clicks from widget content underneath:
767-
only real controls stay interactive, everything else passes through. */
768-
pointer-events: none;
769778
}
770779

771-
/* Capabilities chip stays interactive for its granted-permissions tooltip;
772-
the kind badge and title are display-only and pass clicks through. */
780+
.board-widget__bar > .board-widget__title {
781+
max-width: 200px;
782+
}
783+
784+
/* Every flexible child must shrink inside the capped pill; content that
785+
overflowed the box would carry pointer events into the reserved corner. */
773786
.board-widget__bar > .board-widget__drag-handle,
774-
.board-widget__bar > .board-widget__capabilities,
775787
.board-widget__bar > .board-widget__menu {
776-
pointer-events: auto;
788+
flex-shrink: 0;
789+
}
790+
791+
.board-widget__bar > .board-widget__kind,
792+
.board-widget__bar > .board-widget__capabilities {
793+
min-width: 0;
794+
overflow: hidden;
777795
}
778796

779797
.board-widget__resize-handle {
780798
opacity: 0;
781799
transition:
782-
opacity 120ms ease,
783-
visibility 0s linear 120ms;
800+
opacity 100ms ease,
801+
visibility 0s linear 100ms;
784802
visibility: hidden;
785803
}
786804

805+
/* Hover-intent: the pointer must rest on the card briefly before chrome
806+
appears, so quick clicks into widget content never race the overlay.
807+
Delay-only overrides keep the base fade, and reduced-motion's
808+
transition: none stays authoritative because no transition-property is
809+
redeclared here. */
787810
.board-widget:hover .board-widget__bar,
788-
.board-widget:hover .board-widget__resize-handle,
811+
.board-widget:hover .board-widget__resize-handle {
812+
opacity: 1;
813+
transition-delay: 350ms;
814+
visibility: visible;
815+
}
816+
817+
/* Keyboard focus, an open menu, and active drags need chrome immediately. */
789818
.board-widget:focus-within .board-widget__bar,
790819
.board-widget:focus-within .board-widget__resize-handle,
791820
.board-widget--dragging .board-widget__bar,
792821
.board-widget--dragging .board-widget__resize-handle,
793822
.board-widget:has(.board-widget__menu[open]) .board-widget__bar,
794823
.board-widget:has(.board-widget__menu[open]) .board-widget__resize-handle {
795824
opacity: 1;
796-
/* Delay-only override: reveal flips visibility immediately while the base
797-
shorthand keeps the fade, and reduced-motion's transition: none stays
798-
authoritative because no transition-property is redeclared here. */
799825
transition-delay: 0s;
800826
visibility: visible;
801827
}

0 commit comments

Comments
 (0)