Repository navigation
feat: make cross-column dragged card sortable #1894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andrejsshell
merged 15 commits into
usekaneo:main
from
VictorOnwukwe:feat/cross-column-card-sorting
Oct 5, 2026
+1,088
−273
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8d7afe6
feat: make cross-column dragged card sortable
VictorOnwukwe 006483d
fix: make cross-column drag sort activator key compatible with windows
VictorOnwukwe e7a167f
fix: preserve automatic sorting during cross-column moves
VictorOnwukwe dcc20af
fix: clear stale cross-column drag targets
VictorOnwukwe 16ce2fe
Merge remote-tracking branch 'origin/main' into feat/cross-column-car…
andrejsshell f9980a7
fix(board): preview cross-column drops instead of a modifier key
andrejsshell c3ffa5e
fix(board): keep the dragged card from animating between columns
andrejsshell d094d39
Merge branch 'main' into feat/cross-column-card-sorting
andrejsshell feda70e
fix(board): keep live updates during drags and fill empty drop zones
andrejsshell 7282c09
perf(board): stop re-rendering every card while dragging
andrejsshell f7e9738
perf(board): mount task menus and delete dialogs on first use
andrejsshell 01e3065
fix(board): keep previews honest when a drop would be refused
andrejsshell 1d40c64
fix(board): drop on blank column space where the card is shown
andrejsshell c905658
fix(board): treat column headers as drop targets and cancel off-board…
andrejsshell 62d172d
fix(board): pick drop targets from visible cards in the nearest column
andrejsshell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
apps/web/src/components/kanban-board/board-collision-detection.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import type { ClientRect, DroppableContainer } from "@dnd-kit/core"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
| import { boardCollisionDetection } from "./board-collision-detection"; | ||
|
|
||
| function rect(left: number, top: number, width: number, height: number) { | ||
| return { | ||
| left, | ||
| top, | ||
| width, | ||
| height, | ||
| right: left + width, | ||
| bottom: top + height, | ||
| } as ClientRect; | ||
| } | ||
|
|
||
| const rects = new Map([ | ||
| ["empty", rect(0, 100, 300, 700)], | ||
| ["doing", rect(320, 100, 300, 700)], | ||
| ["c", rect(330, 110, 280, 80)], | ||
| ["d", rect(330, 200, 280, 80)], | ||
| ]); | ||
|
|
||
| const columnData = { | ||
| empty: { type: "column", column: { id: "empty", tasks: [] } }, | ||
| doing: { | ||
| type: "column", | ||
| column: { id: "doing", tasks: [{ id: "c" }, { id: "d" }] }, | ||
| }, | ||
| } as Record<string, unknown>; | ||
|
|
||
| function detect(pointer: { x: number; y: number } | null) { | ||
| const droppableContainers = [...rects.keys()].map( | ||
| (id) => | ||
| ({ | ||
| id, | ||
| disabled: false, | ||
| data: { current: columnData[id] }, | ||
| }) as unknown as DroppableContainer, | ||
| ); | ||
| return boardCollisionDetection({ | ||
| active: { id: "card" } as never, | ||
| collisionRect: rect(100, 120, 300, 80), | ||
| droppableRects: rects, | ||
| droppableContainers, | ||
| pointerCoordinates: pointer, | ||
| }).map((collision) => collision.id); | ||
| } | ||
|
|
||
| describe("boardCollisionDetection", () => { | ||
| it("targets the empty column under the pointer over a closer card", () => { | ||
| expect(detect({ x: 150, y: 160 })).toEqual(["empty"]); | ||
| }); | ||
|
|
||
| it("targets the card under the pointer", () => { | ||
| expect(detect({ x: 400, y: 150 })).toEqual(["c"]); | ||
| }); | ||
|
|
||
| it("targets the last card below a column's cards", () => { | ||
| expect(detect({ x: 400, y: 600 })).toEqual(["d"]); | ||
| }); | ||
|
|
||
| it("targets the nearest card in the gap between cards", () => { | ||
| expect(detect({ x: 400, y: 194 })).toEqual(["c"]); | ||
| expect(detect({ x: 400, y: 197 })).toEqual(["d"]); | ||
| }); | ||
|
|
||
| it("finds nothing when the pointer is between columns", () => { | ||
| expect(detect({ x: 310, y: 160 })).toEqual([]); | ||
| }); | ||
|
|
||
| it("falls back to corner distance without a pointer", () => { | ||
| expect(detect(null)[0]).toBe("c"); | ||
| }); | ||
| }); |
37 changes: 37 additions & 0 deletions
37
apps/web/src/components/kanban-board/board-collision-detection.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { | ||
| type CollisionDetection, | ||
| closestCorners, | ||
| pointerWithin, | ||
| } from "@dnd-kit/core"; | ||
| import type { ProjectWithTasks } from "@/types/project"; | ||
|
|
||
| type ColumnData = { | ||
| type?: string; | ||
| column?: ProjectWithTasks["columns"][number]; | ||
| }; | ||
|
|
||
| export const boardCollisionDetection: CollisionDetection = (args) => { | ||
| const { pointerCoordinates, droppableContainers, droppableRects } = args; | ||
| if (!pointerCoordinates) return closestCorners(args); | ||
|
|
||
| const [hit] = pointerWithin(args); | ||
| const data = droppableContainers.find((container) => container.id === hit?.id) | ||
| ?.data.current as ColumnData | undefined; | ||
| if (data?.type !== "column" || !data.column?.tasks.length) | ||
| return hit ? [hit] : []; | ||
|
|
||
| let closest = hit; | ||
| let closestDistance = Number.POSITIVE_INFINITY; | ||
| for (const task of data.column.tasks) { | ||
| const rect = droppableRects.get(task.id); | ||
| if (!rect) continue; | ||
| const distance = Math.abs( | ||
| rect.top + rect.height / 2 - pointerCoordinates.y, | ||
| ); | ||
| if (distance < closestDistance) { | ||
| closest = { id: task.id }; | ||
| closestDistance = distance; | ||
| } | ||
| } | ||
| return [closest]; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
apps/web/src/components/kanban-board/column/column-sort-hint.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export function ColumnSortHint({ label }: { label: string }) { | ||
| return ( | ||
| <div | ||
| role="status" | ||
| className="pointer-events-none absolute inset-x-3 bottom-3 z-10 rounded-lg border border-border bg-popover/95 px-3 py-2 text-center text-xs font-medium text-popover-foreground shadow-md backdrop-blur-sm" | ||
| > | ||
| {label} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/web/src/components/kanban-board/drag-preview/drag-hover.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export type DragHover = { activeId: string; overId: string }; |
7 changes: 7 additions & 0 deletions
7
apps/web/src/components/kanban-board/drag-preview/find-task-column.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import type { ProjectWithTasks } from "@/types/project"; | ||
|
|
||
| export function findTaskColumn(board: ProjectWithTasks, id: string) { | ||
| return board.columns.find( | ||
| (column) => column.id === id || column.tasks.some((task) => task.id === id), | ||
| ); | ||
| } |
16 changes: 16 additions & 0 deletions
16
apps/web/src/components/kanban-board/drag-preview/get-hovered-other-column-id.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
| import { getHoveredOtherColumnId } from "./get-hovered-other-column-id"; | ||
| import { testBoard } from "./test-board"; | ||
|
|
||
| describe("getHoveredOtherColumnId", () => { | ||
| it("returns the hovered column when it differs from the card's column", () => { | ||
| expect(getHoveredOtherColumnId(testBoard(), "a", "c")).toBe("doing"); | ||
| expect(getHoveredOtherColumnId(testBoard(), "a", "done")).toBe("done"); | ||
| }); | ||
|
|
||
| it("returns null within the card's column or for unknown ids", () => { | ||
| expect(getHoveredOtherColumnId(testBoard(), "a", "b")).toBeNull(); | ||
| expect(getHoveredOtherColumnId(testBoard(), "a", "todo")).toBeNull(); | ||
| expect(getHoveredOtherColumnId(testBoard(), "a", "missing")).toBeNull(); | ||
| }); | ||
| }); |
12 changes: 12 additions & 0 deletions
12
apps/web/src/components/kanban-board/drag-preview/get-hovered-other-column-id.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { ProjectWithTasks } from "@/types/project"; | ||
| import { findTaskColumn } from "./find-task-column"; | ||
|
|
||
| export function getHoveredOtherColumnId( | ||
| board: ProjectWithTasks, | ||
| activeId: string, | ||
| overId: string, | ||
| ) { | ||
| const from = findTaskColumn(board, activeId); | ||
| const to = findTaskColumn(board, overId); | ||
| return from && to && from.id !== to.id ? to.id : null; | ||
| } |
29 changes: 29 additions & 0 deletions
29
apps/web/src/components/kanban-board/drag-preview/get-preview-drop-placement.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
| import { getPreviewDropPlacement } from "./get-preview-drop-placement"; | ||
| import { moveIntoHoveredColumn } from "./move-into-hovered-column"; | ||
| import { testBoard } from "./test-board"; | ||
|
|
||
| const preview = () => moveIntoHoveredColumn(testBoard(), "a", "c")!; | ||
|
|
||
| describe("getPreviewDropPlacement", () => { | ||
| it("keeps the previewed slot when dropped on the card itself", () => { | ||
| expect(getPreviewDropPlacement(preview(), "a", "a")).toEqual({ | ||
| overId: "c", | ||
| insertAfterTarget: false, | ||
| }); | ||
| }); | ||
|
|
||
| it("applies the final sortable hover within the column", () => { | ||
| expect(getPreviewDropPlacement(preview(), "a", "d")).toEqual({ | ||
| overId: "d", | ||
| insertAfterTarget: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("follows a final hover into another column", () => { | ||
| expect(getPreviewDropPlacement(preview(), "a", "done")).toEqual({ | ||
| overId: "done", | ||
| insertAfterTarget: undefined, | ||
| }); | ||
| }); | ||
| }); |
17 changes: 17 additions & 0 deletions
17
apps/web/src/components/kanban-board/drag-preview/get-preview-drop-placement.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import type { ProjectWithTasks } from "@/types/project"; | ||
| import { moveBoardTask } from "../move-task"; | ||
| import { getVisualTaskPlacement } from "./get-visual-task-placement"; | ||
| import { moveIntoHoveredColumn } from "./move-into-hovered-column"; | ||
|
|
||
| export function getPreviewDropPlacement( | ||
| board: ProjectWithTasks, | ||
| activeId: string, | ||
| overId: string, | ||
| ) { | ||
| const settled = | ||
| moveIntoHoveredColumn(board, activeId, overId) ?? | ||
| (overId === activeId | ||
| ? board | ||
| : (moveBoardTask(board, activeId, overId)?.project ?? board)); | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
| return getVisualTaskPlacement(settled, activeId); | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
apps/web/src/components/kanban-board/drag-preview/get-visual-task-placement.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
| import { getVisualTaskPlacement } from "./get-visual-task-placement"; | ||
| import { testBoard } from "./test-board"; | ||
|
|
||
| describe("getVisualTaskPlacement", () => { | ||
| it("places the card before its next neighbor", () => { | ||
| expect(getVisualTaskPlacement(testBoard(), "c")).toEqual({ | ||
| overId: "d", | ||
| insertAfterTarget: false, | ||
| }); | ||
| }); | ||
|
|
||
| it("places the last card after its previous neighbor", () => { | ||
| expect(getVisualTaskPlacement(testBoard(), "d")).toEqual({ | ||
| overId: "c", | ||
| insertAfterTarget: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("targets the column for a card alone in it", () => { | ||
| const board = testBoard(); | ||
| board.columns[1].tasks = board.columns[1].tasks.slice(0, 1); | ||
| expect(getVisualTaskPlacement(board, "c")).toEqual({ | ||
| overId: "doing", | ||
| insertAfterTarget: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it("returns null for an unknown card", () => { | ||
| expect(getVisualTaskPlacement(testBoard(), "missing")).toBeNull(); | ||
| }); | ||
| }); |
19 changes: 19 additions & 0 deletions
19
apps/web/src/components/kanban-board/drag-preview/get-visual-task-placement.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import type { ProjectWithTasks } from "@/types/project"; | ||
| import { findTaskColumn } from "./find-task-column"; | ||
|
|
||
| export function getVisualTaskPlacement( | ||
| project: ProjectWithTasks, | ||
| activeId: string, | ||
| ) { | ||
| const column = findTaskColumn(project, activeId); | ||
| if (!column) return null; | ||
|
|
||
| const index = column.tasks.findIndex((task) => task.id === activeId); | ||
| const nextTask = column.tasks[index + 1]; | ||
| if (nextTask) return { overId: nextTask.id, insertAfterTarget: false }; | ||
|
|
||
| const previousTask = column.tasks[index - 1]; | ||
| if (previousTask) return { overId: previousTask.id, insertAfterTarget: true }; | ||
|
|
||
| return { overId: column.id, insertAfterTarget: undefined }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.