Skip to content

Commit a284e20

Browse files
committed
fix(web): keep settled drop hint inside the sidebar viewport
1 parent e34067e commit a284e20

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CollapsibleSectionHeader } from "../ui/collapsible-section-header";
22
import { useSortable } from "@dnd-kit/sortable";
33
import { CSS } from "@dnd-kit/utilities";
4-
import { type ReactNode } from "react";
4+
import { type ReactNode, useLayoutEffect } from "react";
55
import { cn } from "~/lib/utils";
66
import {
77
animateSidebarLayoutChanges,
@@ -15,13 +15,20 @@ function SortableSidebarMarker(props: {
1515
marker: SidebarListMarker;
1616
className?: string;
1717
children?: ReactNode;
18+
revealOverflow?: boolean;
1819
"data-testid"?: string;
1920
}) {
20-
const { setNodeRef, transform, transition } = useSortable({
21+
const { node, setNodeRef, transform, transition } = useSortable({
2122
id: sidebarMarkerId(props.marker),
2223
disabled: SIDEBAR_SORTABLE_DRAG_DISABLED,
2324
animateLayoutChanges: animateSidebarLayoutChanges,
2425
});
26+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- keeps the projected drop box inside the scroll viewport as drag transforms move it
27+
useLayoutEffect(() => {
28+
if (props.revealOverflow && transform?.y !== undefined) {
29+
node.current?.firstElementChild?.scrollIntoView({ block: "nearest", inline: "nearest" });
30+
}
31+
}, [node, props.revealOverflow, transform?.y]);
2532
return (
2633
<li
2734
ref={setNodeRef}
@@ -50,6 +57,7 @@ export function SidebarSectionPlaceholder(props: {
5057
marker={props.marker}
5158
data-testid={`sidebar-${props.marker}`}
5259
className="relative mx-0.5 -mb-px h-0"
60+
revealOverflow={props.marker === "settled-placeholder" && props.showHint}
5361
>
5462
{props.showHint ? (
5563
<div

0 commit comments

Comments
 (0)