DragAndDrop
Reorderable list with drag and keyboard support
Start Here
Start from the smallest working snippet, then move to interactive examples and the full API contract below.
Styled quick start
Copy this entrypoint first. It includes the imports required to get the component on screen.
<script lang="ts">
import '@dryui/ui/themes/default.css';
import '@dryui/ui/themes/dark.css';
import { DragAndDrop } from '@dryui/ui';
</script>
<DragAndDrop.Root>
<DragAndDrop.Item>...</DragAndDrop.Item>
<DragAndDrop.Handle>...</DragAndDrop.Handle>
</DragAndDrop.Root>Import options
Root package
import { DragAndDrop } from '@dryui/ui'Per-component subpath
import { DragAndDrop } from '@dryui/ui/drag-and-drop'Customize
Use the interactive examples to see common variants, states, and composition patterns before building your own.
Reorderable List
<script lang="ts">
let tasks = $state([
{ id: 1, title: 'Design system tokens', priority: 'High' },
{ id: 2, title: 'Build component library', priority: 'High' },
{ id: 3, title: 'Write documentation', priority: 'Medium' },
{ id: 4, title: 'Add tests', priority: 'Medium' },
{ id: 5, title: 'Publish to npm', priority: 'Low' },
]);
</script>
<DragAndDrop.Root items={tasks} onReorder={(items) => tasks = items} orientation="vertical">
{#each tasks as task, index (task.id)}
<DragAndDrop.Item {index}>
{#snippet children({ isDragging })}
<div class="task-item" style:opacity={isDragging ? 0.5 : 1}>
<DragAndDrop.Handle {index}>⠿</DragAndDrop.Handle>
<span class="task-title">{task.title}</span>
<span class="task-priority">{task.priority}</span>
</div>
{/snippet}
</DragAndDrop.Item>
{/each}
</DragAndDrop.Root>Structure
Compound components always start with DragAndDrop.Root. Use this structure block to understand required wrappers before you wire state or styling.
DragAndDrop.Root DragAndDrop.Item DragAndDrop.Handle
Compose
The full API contract lives here: props, CSS variables, and the public data attributes you can target when styling.
Compound component. Start with DragAndDrop.Root, then add only the parts you need.
DragAndDrop.Root
| Prop | Type | Default | Required | Bindable |
|---|---|---|---|---|
items | T[] | — | ✓ | — |
onReorder | (items: T[]) => void | — | ✓ | — |
orientation | verticalhorizontal | — | — | — |
children | Snippet | — | ✓ | — |
Forwards <div> attributes via rest props. Common examples: id, style, role.
DragAndDrop.Item
| Prop | Type | Default | Required | Bindable |
|---|---|---|---|---|
index | number | — | ✓ | — |
children | Snippet<[{ isDragging: boolean; isOver: boolean }]> | — | ✓ | — |
Forwards <div> attributes via rest props. Common examples: id, style, role. Omitted: children.
DragAndDrop.Handle
| Prop | Type | Default | Required | Bindable |
|---|---|---|---|---|
index | number | — | ✓ | — |
children | Snippet | — | — | — |
Forwards <div> attributes via rest props. Common examples: id, style, role.