You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add case for when `draggedTarget` is `null` and merge `dropover` event code
* Fix live sample
* Fix `columns` variable
* Minor update
* Slight rewrite
* Minor refactor
---------
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Copy file name to clipboardExpand all lines: files/en-us/web/api/html_drag_and_drop_api/kanban_board/index.md
+13-2Lines changed: 13 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,9 +95,15 @@ This defines the basic structure and styles for our application. The tasks are e
95
95
96
96
We want to make the task columns into valid [drop targets](/en-US/docs/Web/API/HTML_Drag_and_Drop_API#drop_target) for the dragged tasks. As a baseline, we need to listen for {{domxref("HTMLElement/dragover_event", "dragover")}} and cancel it. However, we take care and only cancel the event if the drag event is dragging a task—if we are trying to drop anything else, the column should not be a drop target.
Then, declare a `dragover` event handler for each column—this event handler will be expanded later.
105
+
106
+
```js
101
107
columns.forEach((column) => {
102
108
column.addEventListener("dragover", (event) => {
103
109
// Test a custom type we will set later
@@ -177,12 +183,17 @@ function makePlaceholder(draggedTask) {
177
183
}
178
184
```
179
185
180
-
This indicator will be moved around on {{domxref("HTMLElement/dragover_event", "dragover")}}. This is the most complex of all, so we've extracted it into a separate function. We first get the elements we need:
186
+
This indicator will be moved around on {{domxref("HTMLElement/dragover_event", "dragover")}}. This is the most complex of all, so we've extracted it into a separate function. The previous code for the `dragover` event has been moved to this function. We first get the elements we need, safely aborting if the drag is not a task:
181
187
182
188
```js live-sample___kanban
183
189
functionmovePlaceholder(event) {
184
-
constcolumn=event.currentTarget;
190
+
if (!event.dataTransfer.types.includes("task")) {
191
+
return;
192
+
}
193
+
event.preventDefault();
194
+
// Must exist because the ID is added for all drag events with a "task" data entry
0 commit comments