Skip to content

Commit f7c5bd3

Browse files
authored
fix(ui): keep moved toasts clear of mobile header (#131840)
* test(ui): align toast layout assertion with mobile header * fix(ui): refresh toast placement after handoff
1 parent b5acb49 commit f7c5bd3

4 files changed

Lines changed: 82 additions & 21 deletions

File tree

‎ui/src/e2e/native-nav-sidebar-toggle.e2e.test.ts‎

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -911,9 +911,20 @@ suite.define(() => {
911911
await expect.poll(() => navigation.getAttribute("class")).not.toContain("nav-drawer");
912912
});
913913

914-
it.each(["dark", "light"] as const)(
915-
"keeps the toast above the mobile drawer in %s mode",
916-
async (colorScheme) => {
914+
it.each([
915+
{
916+
colorScheme: "dark",
917+
finalLayout: "compact",
918+
finalViewport: { height: 844, width: 390 },
919+
},
920+
{
921+
colorScheme: "light",
922+
finalLayout: "desktop",
923+
finalViewport: { height: 900, width: 1280 },
924+
},
925+
] as const)(
926+
"keeps drawer toast actionable and handed-off toast clear of chat chrome in $finalLayout $colorScheme mode",
927+
async ({ colorScheme, finalLayout, finalViewport }) => {
917928
const page = await openPage({
918929
colorScheme,
919930
height: 844,
@@ -937,31 +948,68 @@ suite.define(() => {
937948
const toast = host.locator(".app-toast");
938949
await toast.waitFor();
939950
await expect.poll(() => toast.textContent()).toContain("Codex hidden");
951+
const drawerToastGeometry = await host.evaluate((node) => {
952+
const toastElement = node.querySelector<HTMLElement>(".app-toast");
953+
return {
954+
computedTop: toastElement
955+
? Math.round(Number.parseFloat(getComputedStyle(toastElement).top))
956+
: null,
957+
placement: node.dataset.toastPlacement,
958+
};
959+
});
960+
expect(drawerToastGeometry.placement).toBe("overlay");
961+
expect(drawerToastGeometry.computedTop).toBe(20);
940962
const dismiss = toast.getByRole("button", { name: "Dismiss" });
941963
await dismiss.click({ trial: true });
942964

943965
await page.screenshot({
944966
animations: "disabled",
945967
path: path.join(TOAST_PROOF_DIR, `mobile-drawer-toast-${colorScheme}.png`),
946968
});
947-
if (colorScheme === "dark") {
969+
if (finalLayout === "compact") {
948970
await page.keyboard.press("Escape");
949971
await expect.poll(() => dialog.isVisible()).toBe(false);
950972
} else {
951-
await page.setViewportSize({ width: 1280, height: 900 });
973+
await page.setViewportSize(finalViewport);
952974
await expect.poll(() => drawer.count()).toBe(0);
953975
}
954-
const retainedToast = page.locator(".shell > openclaw-toast-host .app-toast");
976+
expect(page.viewportSize()).toEqual(finalViewport);
977+
const retainedHost = page.locator(".shell > openclaw-toast-host");
978+
await expect.poll(() => retainedHost.getAttribute("data-toast-placement")).toBe("shell");
979+
const retainedToast = retainedHost.locator(".app-toast");
955980
await expect.poll(() => retainedToast.textContent()).toContain("Codex hidden");
956-
const [toastBounds, composerBounds] = await Promise.all([
957-
retainedToast.boundingBox(),
958-
page.locator(".agent-chat__composer-shell").boundingBox(),
959-
]);
960-
if (!toastBounds || !composerBounds) {
961-
throw new Error("expected the handed-off toast and chat composer to have layout boxes");
981+
if (finalLayout === "compact") {
982+
await expect
983+
.poll(async () => {
984+
const [toastBounds, headerBounds] = await Promise.all([
985+
retainedToast.boundingBox(),
986+
page.locator(".chat-pane__header:visible").first().boundingBox(),
987+
]);
988+
return Boolean(
989+
toastBounds && headerBounds && toastBounds.y >= headerBounds.y + headerBounds.height,
990+
);
991+
})
992+
.toBe(true);
993+
} else {
994+
await expect
995+
.poll(async () => Math.round((await retainedToast.boundingBox())?.y ?? -1))
996+
.toBe(20);
962997
}
963-
expect(Math.round(toastBounds.y)).toBe(20);
964-
expect(toastBounds.y + toastBounds.height).toBeLessThan(composerBounds.y);
998+
await expect
999+
.poll(async () => {
1000+
const [toastBounds, composerBounds] = await Promise.all([
1001+
retainedToast.boundingBox(),
1002+
page.locator(".agent-chat__composer-shell").boundingBox(),
1003+
]);
1004+
return Boolean(
1005+
toastBounds && composerBounds && toastBounds.y + toastBounds.height < composerBounds.y,
1006+
);
1007+
})
1008+
.toBe(true);
1009+
await page.screenshot({
1010+
animations: "disabled",
1011+
path: path.join(TOAST_PROOF_DIR, `handed-off-toast-${finalLayout}-${colorScheme}.png`),
1012+
});
9651013
await retainedToast.getByRole("button", { name: "Dismiss" }).click();
9661014
await expect.poll(() => retainedToast.isVisible()).toBe(false);
9671015
},

‎ui/src/lib/toast.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ class OpenClawToastHost extends OpenClawLightDomContentsElement {
4747
private exitTimer: ReturnType<typeof globalThis.setTimeout> | null = null;
4848
private exitReason: ToastDismissReason | null = null;
4949

50+
private syncPlacement() {
51+
this.dataset.toastPlacement = this.parentElement?.matches(".shell") ? "shell" : "overlay";
52+
}
53+
5054
override connectedCallback() {
5155
super.connectedCallback();
56+
this.syncPlacement();
5257
const pending = queuedToast;
5358
queuedToast = null;
5459
if (pending) {
@@ -66,8 +71,10 @@ class OpenClawToastHost extends OpenClawLightDomContentsElement {
6671
super.disconnectedCallback();
6772
}
6873

69-
/** Keep the active outcome intact while moveBefore() crosses top-layer owners. */
70-
connectedMoveCallback() {}
74+
/** Keep the outcome intact and refresh ancestor-owned placement across moveBefore() handoffs. */
75+
connectedMoveCallback() {
76+
this.syncPlacement();
77+
}
7178

7279
show(options: ToastOptions) {
7380
this.finishDismiss(this.exitReason ?? "replaced");

‎ui/src/pages/chat/chat-responsive.browser.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,9 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
18461846
</div>
18471847
</section>
18481848
</main>
1849-
<openclaw-toast-host><div class="app-toast">Connection notice</div></openclaw-toast-host>
1849+
<openclaw-toast-host data-toast-placement="shell">
1850+
<div class="app-toast">Connection notice</div>
1851+
</openclaw-toast-host>
18501852
</div>
18511853
</body></html>`);
18521854
// The card entrance animation moves every measured descendant together.

‎ui/src/styles/components.css‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,15 +762,19 @@ openclaw-session-owner-chip {
762762
/* A corner toast degenerates at phone widths, where it would span nearly the
763763
* whole viewport anyway. Use the full-width top idiom instead. */
764764
@media (max-width: 768px), (max-width: 932px) and (max-height: 500px) and (orientation: landscape) {
765-
/* The unanchored chat toast shares the viewport with shell and pane chrome.
766-
Anchored permission toasts already carry a measured pane-header offset. */
767-
.shell--chat > openclaw-toast-host .app-toast:not(.app-toast--anchored) {
768-
top: calc(
765+
.shell--chat {
766+
--app-toast-shell-top: calc(
769767
var(--safe-area-top) + var(--shell-topbar-height) + var(--chat-mobile-pane-header-height) +
770768
20px
771769
);
772770
}
773771

772+
/* The unanchored chat toast shares the viewport with shell and pane chrome.
773+
Anchored permission toasts already carry a measured pane-header offset. */
774+
openclaw-toast-host[data-toast-placement="shell"] .app-toast:not(.app-toast--anchored) {
775+
top: var(--app-toast-shell-top, calc(20px + var(--safe-area-top)));
776+
}
777+
774778
.app-toast {
775779
left: max(12px, var(--safe-area-left));
776780
right: max(12px, var(--safe-area-right));

0 commit comments

Comments
 (0)