Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(ui): a hover hint at the foot of the window opens above it (#1098)

lmliheng65615e04b3c5
diff --git a/changelog/unreleased/2026-10-14-context-ring-tooltip.md b/changelog/unreleased/2026-10-14-context-ring-tooltip.md
new file mode 100644
index 00000000..d1bb75ee
--- /dev/null
+++ b/changelog/unreleased/2026-10-14-context-ring-tooltip.md
@@ -0,0 +1,16 @@
+# The context ring's hover hint opens above it
+
+- **Date:** 2026-10-14
+- **Type:** fix
+- **Scope:** `ui`
+
+[中文版](2026-10-14-context-ring-tooltip.zh.md)
+
+Ported from upstream PenguinHarness (#1098, commit `9f9c0df3`).
+
+Hovering the composer's context ring showed its hint under the ring, where the bottom edge of the
+window cut it in half, in every theme. A hint that hangs under a control now opens above it when the
+window has no room for it below and more room above; everywhere else it still opens below. Any hover
+hint on a control at the foot of the window behaves the same way, not only the ring's.
+
+Interfaces and the stored data are unchanged.
diff --git a/changelog/unreleased/2026-10-14-context-ring-tooltip.zh.md b/changelog/unreleased/2026-10-14-context-ring-tooltip.zh.md
new file mode 100644
index 00000000..36a23367
--- /dev/null
+++ b/changelog/unreleased/2026-10-14-context-ring-tooltip.zh.md
@@ -0,0 +1,16 @@
+# 上下文圆环的悬停提示改在上方弹出
+
+- **Date:** 2026-10-14
+- **Type:** fix
+- **Scope:** `ui`
+
+[English](2026-10-14-context-ring-tooltip.md)
+
+移植自上游 PenguinHarness(#1098,提交 `9f9c0df3`)。
+
+悬停输入框的上下文圆环时,提示出现在圆环下方,被窗口底边截去一半,三套主题都是如此。现在,挂在控件下方的
+提示若在下方放不下、而上方空间更大,就改在控件上方弹出 —— 面板以自己的下边缘定位、向上生长,文字折成几行都
+不会被底边裁掉;其余情况仍在下方。窗口底部任何控件的悬停提示都按同样规则处理,不只圆环。改的是共用的
+tooltip,而不是圆环自己。
+
+接口与已存数据都没有变化。
diff --git a/packages/ui/src/components/overlays/tooltip/tooltip.tsx b/packages/ui/src/components/overlays/tooltip/tooltip.tsx
index 702e6c00..e55be6f5 100644
--- a/packages/ui/src/components/overlays/tooltip/tooltip.tsx
+++ b/packages/ui/src/components/overlays/tooltip/tooltip.tsx
@@ -30,7 +30,8 @@
*
* Two geometries, chosen by the shape of the control strip rather than by taste: `right` for
* a vertical rail, `bottom` for a horizontal toolbar, where a panel to the side would cover
- * the very buttons next to the one being asked about.
+ * the very buttons next to the one being asked about. A `bottom` panel with no room under its
+ * trigger — a toolbar at the foot of the window — turns over it instead (`belowTrigger`).
*
* Deliberately NOT `role="tooltip"` + `aria-describedby`: its callers label their triggers
* with the same words it shows, and a description repeating the accessible name makes a
@@ -43,7 +44,7 @@
* scroll and on a resize — the last three because the position is measured once and is stale
* the moment the trigger moves.
*/
-import { useCallback, useEffect, useRef, useState } from "react";
+import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
import { createPortal } from "react-dom";
import type { ReactNode } from "react";
@@ -162,10 +163,12 @@ export interface Viewport {
* what keeps a panel on screen without anyone measuring a width that does not exist until
* after it renders — and `room` is the other half of that: how far the panel may grow from
* its edge before it would cross the margin on the opposite side, the width a long text has
- * to wrap at instead of running off screen.
+ * to wrap at instead of running off screen. Exactly one vertical edge is given too: `top`
+ * hangs the panel down from that point, `bottom` stands it up from there.
*/
export interface PanelPosition {
- top: number;
+ top?: number;
+ bottom?: number;
left?: number;
right?: number;
room: number;
@@ -192,15 +195,26 @@ export function besideTrigger(rect: TriggerRect, viewport: Viewport): PanelPosit
* Under the trigger, aligned to whichever of its vertical edges faces the roomier half of the
* window, so the panel always grows inward. A toolbar button near the right edge of a docked
* panel is the case this exists for: left-aligned there, the panel would run off screen.
+ *
+ * Over the trigger instead when the panel, `height` tall as rendered, would cross the window's
+ * bottom margin and there is more room above: a control at the foot of the window (the
+ * composer's toolbar, with its context ring) would otherwise hang its hint past the bottom
+ * edge. Above, the panel is pinned by its bottom edge, so it grows upward from the trigger
+ * however many lines its text wraps to. Without a height (not rendered yet) it hangs below.
*/
-export function belowTrigger(rect: TriggerRect, viewport: Viewport): PanelPosition {
- const top = rect.bottom + PANEL_GAP;
+export function belowTrigger(rect: TriggerRect, viewport: Viewport, height = 0): PanelPosition {
+ const roomBelow = viewport.height - VIEWPORT_MARGIN - (rect.bottom + PANEL_GAP);
+ const roomAbove = rect.top - PANEL_GAP - VIEWPORT_MARGIN;
+ const vertical =
+ height > roomBelow && roomAbove > roomBelow
+ ? { bottom: viewport.height - rect.top + PANEL_GAP }
+ : { top: rect.bottom + PANEL_GAP };
if (rect.left + rect.width / 2 > viewport.width / 2) {
const right = Math.max(viewport.width - rect.right, VIEWPORT_MARGIN);
- return { top, right, room: Math.max(viewport.width - right - VIEWPORT_MARGIN, 0) };
+ return { ...vertical, right, room: Math.max(viewport.width - right - VIEWPORT_MARGIN, 0) };
}
const left = Math.max(rect.left, VIEWPORT_MARGIN);
- return { top, left, room: Math.max(viewport.width - left - VIEWPORT_MARGIN, 0) };
+ return { ...vertical, left, room: Math.max(viewport.width - left - VIEWPORT_MARGIN, 0) };
}
export function Tooltip({
@@ -229,30 +243,26 @@ export function Tooltip({
}) {
const anchorRef = useRef<HTMLSpanElement>(null);
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
- /** Non-null only while the panel is up; the measured viewport point it hangs from. */
- const [position, setPosition] = useState<PanelPosition | null>(null);
+ /** Non-null only while the panel is up; the trigger's box, measured as it opened. */
+ const [anchor, setAnchor] = useState<TriggerRect | null>(null);
const hide = useCallback(() => {
if (timerRef.current !== null) {
clearTimeout(timerRef.current);
timerRef.current = null;
}
- setPosition(null);
+ setAnchor(null);
}, []);
const show = () => {
if (suppressed === true || timerRef.current !== null) return;
timerRef.current = setTimeout(() => {
timerRef.current = null;
- const anchor = anchorRef.current;
+ const trigger = anchorRef.current;
// Measured now, not when the trigger rendered: whether its label is cut off depends on
// the width it has at this moment.
- if (anchor === null || !hintAllowedFor(anchor)) return;
- const rect = anchor.getBoundingClientRect();
- const viewport = { width: window.innerWidth, height: window.innerHeight };
- setPosition(
- placement === "bottom" ? belowTrigger(rect, viewport) : besideTrigger(rect, viewport),
- );
+ if (trigger === null || !hintAllowedFor(trigger)) return;
+ setAnchor(trigger.getBoundingClientRect());
}, OPEN_DELAY_MS);
};
@@ -264,7 +274,7 @@ export function Tooltip({
useEffect(() => hide, [hide]);
useEffect(() => {
- if (position === null) return;
+ if (anchor === null) return;
// Escape is heard in capture so a focused trigger inside a dialog still dismisses its
// tooltip, and is deliberately NOT stopped: this panel is not a dismissible layer, and
// swallowing the key would keep the dialog behind it open on the same press.
@@ -282,7 +292,7 @@ export function Tooltip({
window.removeEventListener("scroll", hide, true);
window.removeEventListener("resize", hide);
};
- }, [position, hide]);
+ }, [anchor, hide]);
return (
<span
@@ -294,32 +304,55 @@ export function Tooltip({
onBlur={hide}
>
{children}
- {position !== null && (
- <TooltipPanel label={label} position={position} content={content} placement={placement} />
+ {anchor !== null && (
+ <TooltipPanel label={label} anchor={anchor} content={content} placement={placement} />
)}
</span>
);
}
-/** The panel itself, portaled to the body; both ways in render exactly this. */
+/**
+ * The panel itself, portaled to the body; both ways in render exactly this. It places itself
+ * against the trigger's box: beside a rail entry, or under a toolbar control — and over it when
+ * there is no room below, which takes the panel's rendered height. That height is read in the
+ * layout phase, before the first paint, so a panel that belongs above is never seen below.
+ */
function TooltipPanel({
label,
- position,
+ anchor,
content,
placement,
}: {
label: string;
- position: PanelPosition;
+ /** The trigger's viewport box, measured when the panel opened. */
+ anchor: TriggerRect;
content: TooltipContent;
placement: TooltipPlacement;
}) {
+ const panelRef = useRef<HTMLDivElement>(null);
+ const [height, setHeight] = useState(0);
+ // Read at render: the panel closes on any resize, so the window it was placed in is current.
+ const viewport = { width: window.innerWidth, height: window.innerHeight };
+ const position =
+ placement === "right"
+ ? besideTrigger(anchor, viewport)
+ : belowTrigger(anchor, viewport, height);
+ // `offsetHeight`, not the bounding rect: it is the laid-out height whatever the opening
+ // animation does to the panel's transform on its first frame.
+ useLayoutEffect(() => {
+ if (placement === "bottom" && panelRef.current !== null) {
+ setHeight(panelRef.current.offsetHeight);
+ }
+ }, [anchor, label, content, placement]);
return createPortal(
<div
+ ref={panelRef}
data-testid="tooltip"
aria-hidden
style={{
position: "fixed",
top: position.top,
+ bottom: position.bottom,
left: position.left,
right: position.right,
maxWidth: `min(${contentMaxWidth[content]}, ${position.room}px)`,
@@ -359,7 +392,7 @@ export function tooltipRequest(el: Pick<Element, "getAttribute">): TooltipReques
* — a press because the element is being used now, not asked about.
*/
export function TooltipLayer() {
- const [open, setOpen] = useState<(TooltipRequest & { position: PanelPosition }) | null>(null);
+ const [open, setOpen] = useState<(TooltipRequest & { anchor: TriggerRect }) | null>(null);
useEffect(() => {
let current: Element | null = null;
@@ -382,15 +415,7 @@ export function TooltipLayer() {
const el = current;
const request = el === null ? null : tooltipRequest(el);
if (el === null || request === null || !el.isConnected || !hintAllowedFor(el)) return;
- const rect = el.getBoundingClientRect();
- const viewport = { width: window.innerWidth, height: window.innerHeight };
- setOpen({
- ...request,
- position:
- request.placement === "right"
- ? besideTrigger(rect, viewport)
- : belowTrigger(rect, viewport),
- });
+ setOpen({ ...request, anchor: el.getBoundingClientRect() });
}, OPEN_DELAY_MS);
};
const onOver = (e: PointerEvent) => start(holder(e.target));
@@ -430,7 +455,7 @@ export function TooltipLayer() {
return open === null ? null : (
<TooltipPanel
label={open.label}
- position={open.position}
+ anchor={open.anchor}
content={open.content}
placement={open.placement}
/>
diff --git a/packages/ui/test/tooltip.test.ts b/packages/ui/test/tooltip.test.ts
index 5bc7a052..7a385a28 100644
--- a/packages/ui/test/tooltip.test.ts
+++ b/packages/ui/test/tooltip.test.ts
@@ -8,6 +8,13 @@
* text — a background process's command, shown whole — wraps at that room instead of running off
* a phone's screen; a short label never reaches it.
*
+ * Vertically, a panel hangs under a toolbar control, with three cases once its height is known:
+ * - Given a control at the foot of the window (the composer's context ring) and a panel taller
+ * than the room left below it, then the panel stands over the control, pinned by its bottom
+ * edge, instead of running past the window's bottom.
+ * - Given a panel that fits below, then it stays below, however low the control sits.
+ * - Given a panel too tall for either side, then it takes the roomier one.
+ *
* The rule: a hint shows for an element with no visible text of its own, or one whose visible
* text is cut off — never for a label the reader can already read in full.
*
@@ -67,6 +74,28 @@ describe("belowTrigger", () => {
expect(belowTrigger(box(900, 0, 100, 20), VIEWPORT).right).toBe(8);
expect(belowTrigger(box(-20, 0, 100, 20), VIEWPORT).left).toBe(8);
});
+
+ it("stands a panel with no room below over a control at the foot of the window", () => {
+ // The composer's context ring, 21px above the bottom edge, and its one-line hint.
+ expect(belowTrigger(box(40, 747, 32, 32), VIEWPORT, 26)).toEqual({
+ bottom: 61,
+ left: 40,
+ room: 952,
+ });
+ });
+
+ it("keeps a panel that fits below there, however low its control sits", () => {
+ expect(belowTrigger(box(40, 700, 32, 32), VIEWPORT, 26)).toEqual({
+ top: 740,
+ left: 40,
+ room: 952,
+ });
+ });
+
+ it("puts a panel too tall for either side on the roomier one", () => {
+ expect(belowTrigger(box(40, 200, 32, 32), VIEWPORT, 700)).toMatchObject({ top: 240 });
+ expect(belowTrigger(box(40, 560, 32, 32), VIEWPORT, 700)).toMatchObject({ bottom: 248 });
+ });
});
describe("besideTrigger", () => {