Skip to content

Commit 5e57623

Browse files
committed
refactor: reinstate disableAutoScroll behaviour
1 parent 88f0cc7 commit 5e57623

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

packages/core/components/DragDropContext/index.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
useRef,
1212
useState,
1313
} from "react";
14-
import { defaultPreset, DragDropManager } from "@dnd-kit/dom";
14+
import { AutoScroller, defaultPreset, DragDropManager } from "@dnd-kit/dom";
1515
import { DragDropEvents } from "@dnd-kit/abstract";
1616
import { DropZoneProvider } from "../DropZone";
1717
import type { Draggable, Droppable } from "@dnd-kit/dom";
@@ -76,7 +76,15 @@ type DeepestParams = {
7676

7777
const AREA_CHANGE_DEBOUNCE_MS = 100;
7878

79-
const DragDropContextClient = ({ children }: { children: ReactNode }) => {
79+
type DragDropContextProps = {
80+
children: ReactNode;
81+
disableAutoScroll?: boolean;
82+
};
83+
84+
const DragDropContextClient = ({
85+
children,
86+
disableAutoScroll,
87+
}: DragDropContextProps) => {
8088
const { state, config, dispatch, resolveData } = useAppContext();
8189

8290
const [preview, setPreview] = useState<Preview>(null);
@@ -118,7 +126,9 @@ const DragDropContextClient = ({ children }: { children: ReactNode }) => {
118126
};
119127

120128
const [plugins] = useState(() => [
121-
...defaultPreset.plugins,
129+
...(disableAutoScroll
130+
? defaultPreset.plugins.filter((plugin) => plugin !== AutoScroller)
131+
: defaultPreset.plugins),
122132
createNestedDroppablePlugin({
123133
onChange: (params, manager) => {
124134
const lastParams = deepestRef.current;
@@ -473,12 +483,19 @@ const DragDropContextClient = ({ children }: { children: ReactNode }) => {
473483
);
474484
};
475485

476-
export const DragDropContext = ({ children }: { children: ReactNode }) => {
486+
export const DragDropContext = ({
487+
children,
488+
disableAutoScroll,
489+
}: DragDropContextProps) => {
477490
const { status } = useAppContext();
478491

479492
if (status === "LOADING") {
480493
return children;
481494
}
482495

483-
return <DragDropContextClient>{children}</DragDropContextClient>;
496+
return (
497+
<DragDropContextClient disableAutoScroll={disableAutoScroll}>
498+
{children}
499+
</DragDropContextClient>
500+
);
484501
};

packages/core/components/Puck/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ export function Puck<
414414
refreshPermissions: () => null,
415415
}}
416416
>
417-
<DragDropContext>
417+
<DragDropContext disableAutoScroll={dnd?.disableAutoScroll}>
418418
<CustomPuck>
419419
{children || (
420420
<div

0 commit comments

Comments
 (0)