Skip to content

#1853: Fix direction detection for display:contents lists - #2477

Open
Yahiro025 wants to merge 3 commits into
SortableJS:masterfrom
Yahiro025:cursor/fix-display-contents-grid-1211
Open

Yahiro025 wants to merge 3 commits into
SortableJS:masterfrom
Yahiro025:cursor/fix-display-contents-grid-1211

Conversation

@Yahiro025

Copy link
Copy Markdown

Fixes #1853.

Problem. Sortable on a display: contents container inside a CSS grid (especially with an incomplete last row) can place the dragged item at the end of the grid. Setting direction: 'horizontal' or attaching Sortable to the grid itself worked around it.

Root cause. _detectDirection inspects the sortable’s own style. display: contents has no box; children participate in the ancestor’s grid/flex. Block children made the function return vertical. _ghostIsLast then treated “to the right of the item union” as “after the list.”

Fix. Walk past display: contents ancestors (including assignedSlot and a shadow host) and use that ancestor for flex/grid/width. Also treat inline-flex / inline-grid like flex / grid.

Tests. tests/display-contents-grid.html + direction assertions (grid/flex-row → horizontal; flex-col/block/1-col grid → vertical; nested contents and inline-grid → horizontal). Drag item 1 onto item 3 expects 2, 3, 1, 4, 5.

Verification. npm i && NODE_ENV=umd npx rollup -c ./scripts/umd-build.js && npx testcafe chrome:headless tests/Sortable.test.js --reporter spec → 20 passed. Builds not committed.

AI-assisted disclosure. Drafted with AI assistance. Root cause confirmed by detectDirection returning vertical on a contents+grid fixture before the walk-up.

Please merge only to master.

Walk past display:contents (including slotted/shadow wrappers) so
flex/grid direction is taken from the layout-generating ancestor.
testcafe-safe-storage 1.1.6 calls fs.rm, so npm test crashed in
promisify on the Node 10 image before any test ran.
@cursor
cursor Bot force-pushed the cursor/fix-display-contents-grid-1211 branch from 4598ce7 to f4a4793 Compare September 30, 2026 12:37
cimg/node browsers images ship Chrome libraries, not the binary, so
chrome:headless was not found after the Node 18 image change.
@Yahiro025

Copy link
Copy Markdown
Author

Fixes direction detection for display: contents lists (#1853). Branch is merge-clean with no open threads — ready for review or merge whenever you have a chance.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Sortable applied on a css display: contents container behave erratically in certain scenarios

1 participant