fix(pages): keep the section toolbar inside the section so the canvas edge never clips it

The toolbar hung 20 px above the selected section, so it was cut off for the
first section and for any section scrolled to the top of the canvas. It now
sits inside the section's top-right corner, and the hero's image button moves
to the top-left so the two never overlap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-03 17:48:04 +08:00
1 parent be74080492
commit e3d7b7ec4c
3 files changed
+13 -2

No files matched your search

@@ -102,7 +102,7 @@ export function ImageSpot({ index, src, className, corner }: { index: number; sr
<>
{img}
<button type="button" aria-label={t("PagesImage")} onClick={open}
className="absolute top-3 right-3 z-10 flex size-10 cursor-pointer items-center justify-center rounded-full bg-background/90 text-foreground shadow hover:bg-background">
className="absolute top-3 left-3 z-10 flex size-10 cursor-pointer items-center justify-center rounded-full bg-background/90 text-foreground shadow hover:bg-background">
<ImagePlus aria-hidden="true" className="size-5" />
</button>
</>
@@ -118,6 +118,17 @@ describe("VisualEditor", () => {
expect(section(1)).toHaveAttribute("data-selected", "true");
});
// A toolbar hung above the section was clipped at the canvas top (first section, or a section scrolled to the top).
it("keeps the section toolbar inside the section, clear of the hero's image button", async () => {
const canvas = await open();
fireEvent.click(section(0));
const bar = canvas.getByRole("toolbar");
expect(bar.className).not.toMatch(/(^|\s)-top-/);
expect(bar.className).toMatch(/(^|\s)top-2(\s|$)/);
expect(bar.className).toMatch(/(^|\s)right-2(\s|$)/);
expect(within(section(0)).getByRole("button", { name: "Image" }).className).toMatch(/(^|\s)left-3(\s|$)/);
});
it("undoes a delete with Ctrl+Z and redoes it with Ctrl+Shift+Z", async () => {
const canvas = await open();
fireEvent.click(section(2));
@@ -119,7 +119,7 @@ export function VisualEditor({ p, ask }: { p: Draft; ask: Ask }) {
<>
{selected === i ? (
<div role="toolbar" aria-label={t(BLOCK_LABELS[rows[i].block.type])} onClick={(e) => e.stopPropagation()}
className="absolute -top-5 right-2 z-30 flex items-center gap-0.5 rounded-md border bg-popover p-0.5 text-popover-foreground shadow-md">
className="absolute top-2 right-2 z-30 flex items-center gap-0.5 rounded-md border bg-popover p-0.5 text-popover-foreground shadow-md">
<span draggable aria-label={t("PagesDragSection")} title={t("PagesDragSection")}
className="flex size-8 cursor-grab items-center justify-center rounded-md hover:bg-accent"
onDragStart={(e) => { e.dataTransfer.setData("text/plain", String(i)); e.dataTransfer.effectAllowed = "move"; setDrag({ from: i, to: null }); }}