Skip to content

Commit aef5b04

Browse files
committed
Doc updates
1 parent 1f4aeb5 commit aef5b04

File tree

4 files changed

+68
-63
lines changed

4 files changed

+68
-63
lines changed

apps/docs/concepts/drag-drop-manager.mdx

+41-41
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The `DragDropManager` is the central orchestrator of the drag and drop system. I
1111
```js
1212
import {DragDropManager} from '@dnd-kit/dom';
1313

14+
// Create a manager instance
1415
const manager = new DragDropManager();
1516

1617
// Create draggable and droppable elements
@@ -37,66 +38,66 @@ import {
3738
} from '@dnd-kit/dom';
3839

3940
const manager = new DragDropManager({
40-
// Custom sensors for detecting drag interactions
41+
// Sensors detect drag interactions
4142
sensors: [
42-
PointerSensor,
43-
KeyboardSensor,
43+
PointerSensor, // Handles mouse and touch
44+
KeyboardSensor, // Enables keyboard navigation
4445
],
4546

46-
// Plugins to extend functionality
47+
// Plugins extend functionality
4748
plugins: [
48-
AutoScroller,
49-
Accessibility,
49+
AutoScroller, // Automatic scrolling during drag
50+
Accessibility, // ARIA attributes management
5051
],
5152

52-
// Modifiers to customize drag behavior
53+
// Modifiers customize drag behavior
5354
modifiers: [
54-
restrictToWindow,
55+
restrictToWindow, // Keeps dragged items within window bounds
5556
],
5657
});
5758
```
5859

5960
## Default Configuration
6061

61-
By default, the manager includes:
62+
The manager includes these defaults out of the box:
6263

6364
### Sensors
64-
- `PointerSensor`: Handles mouse and touch interactions with:
65-
- Mouse: Immediate activation on drag handle
66-
- Touch: 250ms delay with 5px tolerance
65+
- `PointerSensor`: Handles mouse and touch interactions
66+
- Mouse: Activates immediately on drag handle
67+
- Touch: 250ms delay with 5px movement tolerance
6768
- Other pointers: 200ms delay with 5px distance threshold
6869

69-
- `KeyboardSensor`: Enables keyboard navigation
70+
- `KeyboardSensor`: Enables keyboard navigation with arrow keys
7071

7172
### Plugins
72-
- `Accessibility`: Manages ARIA attributes
73-
- `AutoScroller`: Handles automatic scrolling
74-
- `Cursor`: Updates cursor styles
75-
- `Feedback`: Manages drag feedback
73+
- `Accessibility`: Manages ARIA attributes and announcements for screen readers
74+
- `AutoScroller`: Scrolls containers when dragging near edges
75+
- `Cursor`: Updates cursor appearance during drag
76+
- `Feedback`: Controls visual feedback during drag
7677
- `PreventSelection`: Prevents text selection while dragging
77-
- `ScrollListener`: Tracks scroll events
78+
- `ScrollListener`: Monitors scroll events during drag
7879
- `Scroller`: Handles programmatic scrolling
7980

8081
## Events
8182

82-
The manager's `monitor` property allows you to listen for drag and drop events:
83+
The manager's `monitor` lets you observe drag and drop events:
8384

8485
```js
85-
// Listen for when dragging starts
86+
// Observe drag start
8687
manager.monitor.addEventListener('beforedragstart', (event) => {
87-
// Can prevent the drag from starting
88+
// Optionally prevent dragging
8889
if (shouldPreventDrag(event.operation.source)) {
8990
event.preventDefault();
9091
}
9192
});
9293

93-
// Listen for drag movement
94+
// Track movement
9495
manager.monitor.addEventListener('dragmove', (event) => {
9596
const {source, position} = event.operation;
9697
console.log(`Dragging ${source.id} to ${position.current}`);
9798
});
9899

99-
// Listen for collisions with droppable targets
100+
// Detect collisions
100101
manager.monitor.addEventListener('collision', (event) => {
101102
const [firstCollision] = event.collisions;
102103
if (firstCollision) {
@@ -117,29 +118,28 @@ manager.monitor.addEventListener('dragend', (event) => {
117118

118119
| Event | Description | Preventable | Data |
119120
|-------|-------------|-------------|------|
120-
| `beforedragstart` | Fired before dragging begins | Yes | `operation` |
121-
| `dragstart` | Fired when dragging starts | No | `operation`, `nativeEvent` |
122-
| `dragmove` | Fired when dragging element moves | Yes | `operation`, `to`, `by`, `nativeEvent` |
123-
| `dragover` | Fired when hovering over a droppable | Yes | `operation` |
124-
| `collision` | Fired when colliding with droppables | Yes | `collisions` |
125-
| `dragend` | Fired when dragging ends | No | `operation`, `canceled`, `nativeEvent` |
121+
| `beforedragstart` | Fires before drag begins | Yes | `operation` |
122+
| `dragstart` | Fires when drag starts | No | `operation`, `nativeEvent` |
123+
| `dragmove` | Fires during movement | Yes | `operation`, `to`, `by`, `nativeEvent` |
124+
| `dragover` | Fires when over a droppable | Yes | `operation` |
125+
| `collision` | Fires on droppable collision | Yes | `collisions` |
126+
| `dragend` | Fires when drag ends | No | `operation`, `canceled`, `nativeEvent` |
126127

127128
## Registration
128129

129-
The manager's `registry` handles registration of draggable and droppable elements:
130+
The manager's `registry` tracks draggable and droppable elements:
130131

131132
```js
132-
// Manual registration
133+
// Manual registration when needed
133134
const cleanup = manager.registry.register(draggable);
134135

135-
// Later cleanup
136+
// Cleanup when done
136137
cleanup();
137-
138138
// Or unregister directly
139139
manager.registry.unregister(draggable);
140140
```
141141

142-
Elements are automatically registered when created with a manager reference:
142+
Elements auto-register when created with a manager reference:
143143

144144
```js
145145
// Auto-registers with manager
@@ -154,11 +154,11 @@ const droppable = new Droppable({
154154
element,
155155
}, manager);
156156

157-
// Prevent auto-registration
157+
// Opt out of auto-registration
158158
const draggable = new Draggable({
159159
id: 'draggable-1',
160160
element,
161-
register: false // Prevent auto-registration
161+
register: false
162162
}, manager);
163163
```
164164

@@ -184,7 +184,7 @@ The `DragDropManager` constructor accepts the following configuration:
184184

185185
The manager instance provides these key properties:
186186

187-
- `registry`: Registry of all draggable and droppable elements
187+
- `registry`: Tracks active elements and extensions
188188
- `draggables`: Map of registered draggable elements
189189
- `droppables`: Map of registered droppable elements
190190
- `plugins`: Registry of active plugins
@@ -198,11 +198,11 @@ The manager instance provides these key properties:
198198
- `status`: Current operation status
199199
- `canceled`: Whether operation was canceled
200200

201-
- `monitor`: Event monitor for drag operations
202-
- `addEventListener`: Register event listener
203-
- `removeEventListener`: Remove event listener
201+
- `monitor`: Event system
202+
- `addEventListener`: Add event listener
203+
- `removeEventListener`: Remove listener
204204

205-
- `renderer`: Handles visual updates during drag operations
205+
- `renderer`: Integration with asynchronous renderers such as React.
206206

207207
### Methods
208208

apps/docs/concepts/draggable.mdx

+9-11
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ By default, the entire element can be used to initiate dragging. You can restric
4545
const element = document.createElement('div');
4646
const handle = document.createElement('div');
4747
handle.classList.add('handle');
48+
handle.innerHTML = ''; // Three dots menu icon for drag handle
4849

4950
element.appendChild(handle);
5051

@@ -64,11 +65,8 @@ You can assign types to draggable elements to restrict which [droppable targets]
6465
const draggable = new Draggable({
6566
id: 'draggable-1',
6667
element,
67-
type: 'item',
68+
type: 'item', // Only droppables accepting 'item' type will be valid targets
6869
}, manager);
69-
70-
// Only droppable targets that accept 'item' type
71-
// will allow this element to be dropped
7270
```
7371

7472
## Feedback
@@ -84,10 +82,10 @@ const draggable = new Draggable({
8482
```
8583

8684
Available feedback options:
87-
- `'default'`: The original element moves with the drag
88-
- `'clone'`: A copy of the element stays in place while the original moves
89-
- `'move'`: The element moves without a placeholder
90-
- `'none'`: No visual feedback
85+
- `'default'`: The original element moves with the drag (best for most cases)
86+
- `'clone'`: A copy of the element stays in place while the original moves (good for drag-to-copy)
87+
- `'move'`: The element moves without a placeholder (minimal visual feedback)
88+
- `'none'`: No visual feedback (useful for custom drag overlays)
9189

9290
## API Reference
9391

@@ -104,15 +102,15 @@ The `Draggable` class accepts the following arguments:
104102
</ParamField>
105103

106104
<ParamField path="handle" type="Element">
107-
Optionally specify a drag handle element. If not provided, the entire element will be draggable. See [drag handles](#drag-handles).
105+
Optionally specify a drag handle element. If not provided, the entire element will be draggable. See [drag handles](#handles).
108106
</ParamField>
109107

110108
<ParamField path="type" type="string | number | Symbol">
111109
Optionally assign a type to restrict which droppable targets can accept this element. See [types](#types).
112110
</ParamField>
113111

114112
<ParamField path="feedback" type="'default' | 'clone' | 'move' | 'none'">
115-
Specify how the element should behave while being dragged. See [drag feedback](#drag-feedback).
113+
Specify how the element should behave while being dragged. See [feedback](#feedback).
116114
</ParamField>
117115

118116
<ParamField path="disabled" type="boolean">
@@ -152,4 +150,4 @@ The `Draggable` instance provides these key properties:
152150

153151
- `register()`: Register this draggable with the manager
154152
- `unregister()`: Remove this draggable from the manager
155-
- `destroy()`: Clean up this draggable instance
153+
- `destroy()`: Clean up this draggable instance and remove all listeners

apps/docs/concepts/droppable.mdx

+17-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ const droppable = new Droppable({
2727
}, manager);
2828

2929
document.body.appendChild(element);
30+
31+
// Listen for drop events
32+
manager.monitor.addEventListener('dragend', (event) => {
33+
if (event.operation.target?.id === droppable.id) {
34+
console.log('Item dropped!', event.operation.source);
35+
}
36+
});
3037
```
3138
3239
## Accepting Specific Types
@@ -63,7 +70,7 @@ const droppable = new Droppable({
6370
6471
By default, the `Droppable` class uses rectangle intersection to detect when draggable elements are over the drop target:
6572
66-
<img src="/images/droppable/shape-intersection.svg" />
73+
<img src="/images/droppable/shape-intersection.svg" alt="Rectangle intersection collision detection" />
6774
6875
You can customize this behavior with different collision detection algorithms:
6976
@@ -82,13 +89,13 @@ const droppable = new Droppable({
8289
}, manager);
8390
```
8491
85-
For example, the `closestCenter` detector will detect collisions based on the distance between the center points:
92+
For example, the `closestCenter` detector will detect collisions based on the distance between the center points, which is ideal for card stacking:
8693
87-
<img src="/images/droppable/closest-center.svg" />
94+
<img src="/images/droppable/closest-center.svg" alt="Closest center collision detection" />
8895
8996
### Collision Priority
9097
91-
When multiple droppable targets overlap, you can set priority to determine which one should receive the drop:
98+
When multiple droppable targets overlap, you can set priority to determine which one should receive the drop. This is particularly useful for nested containers:
9299
93100
```js
94101
const container = new Droppable({
@@ -124,14 +131,14 @@ The `Droppable` class accepts the following arguments:
124131
125132
<ParamField path="collisionDetector" type="CollisionDetector">
126133
A function to determine when draggable elements are over this target. See [collision detection](#collision-detection) for built-in options, such as:
127-
- `shapeIntersection`
128-
- `pointerIntersection`
129-
- `closestCenter`
130-
- `directionBiased`
134+
- `shapeIntersection`: Default, uses rectangle intersection
135+
- `pointerIntersection`: Uses pointer position for precise detection
136+
- `closestCenter`: Uses center point distance, ideal for card stacking
137+
- `directionBiased`: Considers drag direction, useful for sortable lists
131138
</ParamField>
132139
133140
<ParamField path="collisionPriority" type="number">
134-
Priority level when multiple droppable targets overlap. See [collision priority](#collision-priority) for more details.
141+
Priority level when multiple droppable targets overlap. Higher numbers take precedence. See [collision priority](#collision-priority) for more details.
135142
</ParamField>
136143
137144
<ParamField path="disabled" type="boolean">
@@ -163,4 +170,4 @@ The `Droppable` instance provides these key properties:
163170
- `refreshShape()`: Recalculate the target's dimensions
164171
- `register()`: Register this target with the manager
165172
- `unregister()`: Remove this target from the manager
166-
- `destroy()`: Clean up this droppable instance
173+
- `destroy()`: Clean up this droppable instance and remove all listeners

apps/docs/overview.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Overview
3-
description: 'Learn how to build drop interfaces with <span class="inline-logo">**dnd kit**</span>'
3+
description: 'Learn how to build drag and drop interfaces with <span class="inline-logo">**dnd kit**</span>'
44
---
55

66
<img

0 commit comments

Comments
 (0)