apps/docs/extend/plugins/auto-scroller.mdx
The AutoScroller plugin automatically scrolls scrollable containers when the pointer approaches their edges during a drag operation. It works in conjunction with the internal Scroller plugin that detects scrollable ancestors and computes scroll intent.
This plugin is included by default when creating a new DragDropManager.
When a drag operation is in progress and the pointer is near the edge of a scrollable container, the AutoScroller will:
The scroll speed increases as the pointer gets closer to the edge of the container.
Use AutoScroller.configure() to customize the scroll speed and activation zone:
const manager = new DragDropManager({ plugins: (defaults) => [ ...defaults, AutoScroller.configure({ acceleration: 15, threshold: { x: 0, y: 0.3 }, }), ], });
```tsx React
import {DragDropProvider} from '@dnd-kit/react';
import {AutoScroller} from '@dnd-kit/dom';
function App() {
return (
<DragDropProvider
plugins={(defaults) => [
...defaults,
AutoScroller.configure({
acceleration: 15,
threshold: { x: 0, y: 0.3 },
}),
]}
>
</DragDropProvider>
);
}
<script setup>
import {DragDropProvider} from '@dnd-kit/vue';
import {AutoScroller} from '@dnd-kit/dom';
</script>
<template>
<DragDropProvider
:plugins="(defaults) => [...defaults, AutoScroller.configure({ acceleration: 15, threshold: { x: 0, y: 0.3 } })]"
>
<!-- ... -->
</DragDropProvider>
</template>
<script>
import {DragDropProvider} from '@dnd-kit/svelte';
import {AutoScroller} from '@dnd-kit/dom';
</script>
<DragDropProvider
plugins={(defaults) => [...defaults, AutoScroller.configure({ acceleration: 15, threshold: { x: 0, y: 0.3 } })]}
>
<!-- ... -->
</DragDropProvider>
import {DragDropProvider} from '@dnd-kit/solid';
import {AutoScroller} from '@dnd-kit/dom';
function App() {
return (
<DragDropProvider
plugins={(defaults) => [
...defaults,
AutoScroller.configure({
acceleration: 15,
threshold: { x: 0, y: 0.3 },
}),
]}
>
</DragDropProvider>
);
}
A single number applies to both axes. Use { x, y } for per-axis control. Setting an axis to 0 disables auto-scrolling on that axis.
</ParamField>
To disable auto-scrolling, omit the AutoScroller from the plugins array:
const manager = new DragDropManager({ plugins: (defaults) => defaults.filter((plugin) => plugin !== AutoScroller), });
```tsx React
import {DragDropProvider} from '@dnd-kit/react';
import {AutoScroller} from '@dnd-kit/dom';
function App() {
return (
<DragDropProvider
plugins={(defaults) => defaults.filter((plugin) => plugin !== AutoScroller)}
>
</DragDropProvider>
);
}
<script setup>
import {DragDropProvider} from '@dnd-kit/vue';
import {AutoScroller} from '@dnd-kit/dom';
</script>
<template>
<DragDropProvider
:plugins="(defaults) => defaults.filter((plugin) => plugin !== AutoScroller)"
>
<!-- ... -->
</DragDropProvider>
</template>
<script>
import {DragDropProvider} from '@dnd-kit/svelte';
import {AutoScroller} from '@dnd-kit/dom';
</script>
<DragDropProvider
plugins={(defaults) => defaults.filter((plugin) => plugin !== AutoScroller)}
>
<!-- ... -->
</DragDropProvider>
import {DragDropProvider} from '@dnd-kit/solid';
import {AutoScroller} from '@dnd-kit/dom';
function App() {
return (
<DragDropProvider
plugins={(defaults) => defaults.filter((plugin) => plugin !== AutoScroller)}
>
</DragDropProvider>
);
}
To dynamically disable auto-scrolling at runtime, access the plugin instance from the manager registry and call its disable() method:
const manager = new DragDropManager(); const autoScroller = manager.registry.plugins.get(AutoScroller);
// Disable auto-scrolling autoScroller.disable();
// Re-enable auto-scrolling autoScroller.enable();
```tsx React
import {useDragDropManager} from '@dnd-kit/react';
import {AutoScroller} from '@dnd-kit/dom';
function AutoScrollToggle() {
const manager = useDragDropManager();
const autoScroller = manager.registry.plugins.get(AutoScroller);
return (
<button onClick={() => {
autoScroller.disabled
? autoScroller.enable()
: autoScroller.disable();
}}>
Toggle auto-scroll
</button>
);
}
<script setup>
import {useDragDropManager} from '@dnd-kit/vue';
import {AutoScroller} from '@dnd-kit/dom';
const manager = useDragDropManager();
const autoScroller = manager.registry.plugins.get(AutoScroller);
function toggle() {
autoScroller.disabled
? autoScroller.enable()
: autoScroller.disable();
}
</script>
<template>
<button @click="toggle">Toggle auto-scroll</button>
</template>
<script>
import {getDragDropManager} from '@dnd-kit/svelte';
import {AutoScroller} from '@dnd-kit/dom';
const manager = getDragDropManager();
const autoScroller = manager.registry.plugins.get(AutoScroller);
function toggle() {
autoScroller.disabled
? autoScroller.enable()
: autoScroller.disable();
}
</script>
<button onclick={toggle}>Toggle auto-scroll</button>
import {useDragDropManager} from '@dnd-kit/solid';
import {AutoScroller} from '@dnd-kit/dom';
function AutoScrollToggle() {
const manager = useDragDropManager();
const autoScroller = manager.registry.plugins.get(AutoScroller);
return (
<button onClick={() => {
autoScroller.disabled
? autoScroller.enable()
: autoScroller.disable();
}}>
Toggle auto-scroll
</button>
);
}