From ff4e42f1ae06195989665b053e814c9a0e81c710 Mon Sep 17 00:00:00 2001 From: iris Date: Sun, 22 Nov 2026 17:14:34 +0100 Subject: [PATCH] swarm-ui: opening a dialog no longer scrolls the page to the top --- .../packages/swarm-ui/src/ui/dialog/Dialog.css | 4 +++- .../packages/swarm-ui/test/dialog-css.test.mjs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 frontend/packages/swarm-ui/test/dialog-css.test.mjs diff --git a/frontend/packages/swarm-ui/src/ui/dialog/Dialog.css b/frontend/packages/swarm-ui/src/ui/dialog/Dialog.css index 8598b4404..4c80e62af 100644 --- a/frontend/packages/swarm-ui/src/ui/dialog/Dialog.css +++ b/frontend/packages/swarm-ui/src/ui/dialog/Dialog.css @@ -19,7 +19,9 @@ `fit-content` sizing — `max-width` has the same carving-out requirement `width` did. */ box-sizing: border-box; - position: relative; + /* No `position` here: a modal dialog is `position: fixed` by default, which + also anchors the close button below. Setting `relative` put the dialog in + the page's flow, and focusing it on open scrolled the page to the top. */ width: fit-content; --ui-dialog-width: min(90vw, 64em); max-width: var(--ui-dialog-width); diff --git a/frontend/packages/swarm-ui/test/dialog-css.test.mjs b/frontend/packages/swarm-ui/test/dialog-css.test.mjs new file mode 100644 index 000000000..f432ed789 --- /dev/null +++ b/frontend/packages/swarm-ui/test/dialog-css.test.mjs @@ -0,0 +1,18 @@ +// A modal `` is `position: fixed` by default. Setting `position` on the +// `.ui-dialog` rule puts it in the page's flow, and focusing it on open then +// scrolls the page to the top. Run by `npm test`. +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { test } from "node:test"; + +const css = readFileSync( + new URL("../src/ui/dialog/Dialog.css", import.meta.url), + "utf8", +); + +test("the dialog rule leaves its position to the browser", () => { + const rule = css.match(/\.ui-dialog \{([^}]*)\}/); + assert.ok(rule, "the .ui-dialog rule exists"); + const declarations = rule[1].replace(/\/\*[\s\S]*?\*\//g, ""); + assert.doesNotMatch(declarations, /(^|[\s;])position\s*:/); +});