Skip to content

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

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

#1853: Fix direction detection for display:contents lists#2477
Yahiro025 wants to merge 1 commit 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.

Co-authored-by: Bennett Payoyo <Yahiro025@users.noreply.github.com>
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

2 participants