swarm ui: a popover stays on the page, and the ssh popover folds its explanations
A popover hung from its anchor and ran off the foot of the window when the anchor sat low. It now goes over the anchor when it fits neither way better below, and otherwise takes the roomier side with its height cut so it scrolls inside itself; the placement is a pure function with a test, and the box places itself again when its content changes size. The ssh popover showed three long paragraphs above its switch: the explainer and the host-key text now sit in a folded how it works section, and the warning and the switch stay visible. Its sections can no longer give the popover a sideways scroll.
This commit is contained in:
parent
3be4ec069c
commit
da187f8368
1 changed files with 136 additions and 32 deletions
|
|
@ -3,7 +3,10 @@
|
|||
// imported as it is.
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { clampLeft } from "../src/ui/table/popover-position.ts";
|
||||
import {
|
||||
clampLeft,
|
||||
placeVertically,
|
||||
} from "../src/ui/table/popover-position.ts";
|
||||
|
||||
test("a popover near the right edge is pulled back on screen", () => {
|
||||
// 300 wide in a 1000 wide window: the right edge may reach 992.
|
||||
|
|
@ -15,3 +18,32 @@ test("a popover never goes past the left edge", () => {
|
|||
assert.equal(clampLeft(5, 300, 1000), 8);
|
||||
assert.equal(clampLeft(50, 2000, 1000), 8);
|
||||
});
|
||||
|
||||
// A 600 tall window, a badge from 300 to 330, a gap of 4 and an edge of 8:
|
||||
// 258 is free under it and 288 over it.
|
||||
test("a popover that fits under its anchor goes there", () => {
|
||||
assert.deepEqual(placeVertically(300, 330, 200, 600, 4), {
|
||||
top: 334,
|
||||
maxHeight: 258,
|
||||
});
|
||||
});
|
||||
|
||||
test("one that does not fit under goes over when there is more room there", () => {
|
||||
assert.deepEqual(placeVertically(300, 330, 280, 600, 4), {
|
||||
top: 16,
|
||||
maxHeight: 288,
|
||||
});
|
||||
});
|
||||
|
||||
test("one taller than either side is cut to the roomier side and scrolls", () => {
|
||||
// Over the anchor: 288 free, so it is 288 tall and ends 4 above it.
|
||||
assert.deepEqual(placeVertically(300, 330, 900, 600, 4), {
|
||||
top: 8,
|
||||
maxHeight: 288,
|
||||
});
|
||||
// Near the top there is more room under it: it stays there, cut short.
|
||||
assert.deepEqual(placeVertically(20, 50, 900, 600, 4), {
|
||||
top: 54,
|
||||
maxHeight: 538,
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue