Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { render } from "../../test/render";
3import { createSidebarListMotion } from "./Sidebar.motion";
4
5describe("sidebar list motion", () => {
6 it("slides rows above a removal at the bottom instead of jumping with the scroll clamp", async () => {
7 await using screen = await render(null);
8 const viewport = document.createElement("div");
9 viewport.dataset.slot = "scroll-area-viewport";
10 viewport.style.cssText = "height: 200px; overflow-y: auto; overflow-anchor: none";
11 const list = document.createElement("ul");
12 list.style.cssText = "position: relative; margin: 0; padding: 0; list-style: none";
13 const rows = Array.from({ length: 10 }, () => {
14 const row = document.createElement("li");
15 row.style.height = "64px";
16 list.append(row);
17 return row;
18 });
19 viewport.append(list);
20 screen.container.append(viewport);
21 const motion = createSidebarListMotion(list);
22 using _motion = { [Symbol.dispose]: () => motion.dispose() };
23 motion.update(false);
24 viewport.scrollTop = viewport.scrollHeight;
25 viewport.dispatchEvent(new Event("scroll"));
26 const above = rows[7]!;
27 const before = above.getBoundingClientRect().top;
28
29 rows[8]!.remove();
30 motion.update(true);
31 for (const animation of above.getAnimations()) animation.pause();
32
33 expect(above.getBoundingClientRect().top).toBe(before);
34 });
35});