GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): dragging a thread no longer scrolls the sidebar to the bottom · samnab/t3code@03bf95d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components/sidebar
    • SidebarListMarkers.browser.test.tsx
    • SidebarListMarkers.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/sidebar/SidebarListMarkers.browser.test.tsx‎

Copy file name to clipboard
+78Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { DndContext, PointerSensor, useSensor, useSensors } from "@dnd-kit/core";
2+
import { SortableContext, useSortable, type SortingStrategy } from "@dnd-kit/sortable";
3+
import { describe, expect, it, vi } from "vite-plus/test";
4+
import { render } from "../../../test/render";
5+
import { sidebarMarkerId } from "../Sidebar.logic";
6+
import { SidebarSectionPlaceholder } from "./SidebarListMarkers";
7+
8+
// The sidebar strategy gives every item a transform once a drag starts.
9+
const stationary: SortingStrategy = () => ({ x: 0, y: 0, scaleX: 1, scaleY: 1 });
10+
11+
function Row() {
12+
const { setNodeRef, listeners } = useSortable({ id: "row" });
13+
return (
14+
<li ref={setNodeRef} {...listeners} data-testid="row" style={{ height: 40 }}>
15+
Row
16+
</li>
17+
);
18+
}
19+
20+
function Fixture() {
21+
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 1 } }));
22+
return (
23+
<DndContext sensors={sensors} autoScroll={false}>
24+
<SortableContext
25+
items={["row", sidebarMarkerId("settled-placeholder")]}
26+
strategy={stationary}
27+
>
28+
<div data-testid="scroller" style={{ height: 160, overflow: "auto" }}>
29+
<ul>
30+
<Row />
31+
<li style={{ height: 2000 }} />
32+
<SidebarSectionPlaceholder
33+
marker="settled-placeholder"
34+
label="Settled"
35+
showHint
36+
isDropTarget={false}
37+
/>
38+
</ul>
39+
</div>
40+
</SortableContext>
41+
</DndContext>
42+
);
43+
}
44+
45+
function pointer(type: string, target: EventTarget, y: number) {
46+
target.dispatchEvent(
47+
new PointerEvent(type, {
48+
bubbles: true,
49+
cancelable: true,
50+
isPrimary: true,
51+
pointerId: 1,
52+
button: 0,
53+
buttons: type === "pointerup" ? 0 : 1,
54+
clientX: 10,
55+
clientY: y,
56+
}),
57+
);
58+
}
59+
60+
describe("SidebarSectionPlaceholder", () => {
61+
it("leaves the list scroll alone when a drag starts with the drop hint far out of view", async () => {
62+
await using screen = await render(<Fixture />, { router: false });
63+
const scroller = screen.getByTestId("scroller").element();
64+
const row = screen.getByTestId("row").element();
65+
const { top } = row.getBoundingClientRect();
66+
67+
pointer("pointerdown", row, top + 5);
68+
pointer("pointermove", document, top + 15);
69+
const hint = screen.getByTestId("sidebar-settled-placeholder").element();
70+
// The reveal effect runs in the same commit that applies the drag transform.
71+
await vi.waitFor(() =>
72+
expect(getComputedStyle(hint).transform !== "none" || scroller.scrollTop !== 0).toBe(true),
73+
);
74+
75+
expect(scroller.scrollTop).toBe(0);
76+
pointer("pointerup", document, top + 15);
77+
});
78+
});
Collapse file

‎apps/web/src/components/sidebar/SidebarListMarkers.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/sidebar/SidebarListMarkers.tsx
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CollapsibleSectionHeader } from "../ui/collapsible-section-header";
2+
import { getScrollableAncestors } from "@dnd-kit/core";
23
import { useSortable } from "@dnd-kit/sortable";
34
import { CSS } from "@dnd-kit/utilities";
45
import { type ReactNode, useLayoutEffect } from "react";
@@ -24,8 +25,13 @@ function SortableSidebarMarker(props: {
2425
});
2526
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- keeps the projected drop box inside the scroll viewport as drag transforms move it
2627
useLayoutEffect(() => {
27-
if (props.revealOverflow && transform?.y !== undefined) {
28-
node.current?.firstElementChild?.scrollIntoView({ block: "nearest", inline: "nearest" });
28+
const hint = node.current?.firstElementChild;
29+
if (!props.revealOverflow || transform?.y === undefined || !hint) return;
30+
const viewport = getScrollableAncestors(hint, 1)[0]?.getBoundingClientRect();
31+
const box = hint.getBoundingClientRect();
32+
// Only nudge a hint already clipped at the edge; revealing one far off view yanks the list to it.
33+
if (viewport && box.bottom > viewport.top && box.top < viewport.bottom) {
34+
hint.scrollIntoView({ block: "nearest", inline: "nearest" });
2935
}
3036
}, [node, props.revealOverflow, transform?.y]);
3137
return (

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.