Skip to content

Conversation

@STRML
Copy link
Collaborator

@STRML STRML commented Dec 9, 2025

Summary

Implements wrap mode compaction where items flow left-to-right and wrap to the next row, similar to words in a paragraph. This is a v2 reimplementation of the algorithm from PR #1773 by @JohnThomson, adapted to the new composable Compactor interface.

Behavior:

  • Items flow left-to-right, wrapping to the next row at the grid edge
  • Moving an item earlier in the sequence shifts other items right/down
  • Moving an item later in the sequence shifts other items left/up
  • Works best with uniformly-sized items (especially 1x1)

Changes:

  • Added wrapCompactor and wrapOverlapCompactor to react-grid-layout/extras
  • Added "wrap" to the CompactType union type
  • Updated sortLayoutItems() to handle wrap type
  • 20 new tests covering wrap compaction behavior

Usage

import { wrapCompactor } from 'react-grid-layout/extras';

<GridLayout
  compactor={wrapCompactor}
  layout={layout}
  // ...
/>

Test plan

  • All existing tests pass (366 tests)
  • New wrap compactor tests pass (20 tests)
  • Build succeeds
  • Lint passes

Closes #1773

Implements wrap mode compaction where items flow left-to-right and wrap
to the next row, similar to words in a paragraph. When dragging:
- Moving an item earlier shifts other items right/down
- Moving an item later shifts other items left/up

This is a v2 reimplementation of the algorithm from PR #1773 by
@JohnThomson, adapted to the new composable Compactor interface.

Usage:
```tsx
import { wrapCompactor } from 'react-grid-layout/extras';
<GridLayout compactor={wrapCompactor} ... />
```
@github-actions github-actions bot added the tests use this label for changes in tests label Dec 9, 2025
Change credit from @nicosayer to @dmj900501 who is the actual author
of the GridBackground feature PR.
@github-actions github-actions bot added the documentation use this label for changes in documentation label Dec 9, 2025
@STRML STRML merged commit 714f71a into master Dec 10, 2025
4 checks passed
@STRML STRML deleted the compactTypeWrap-v2 branch December 10, 2025 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation use this label for changes in documentation tests use this label for changes in tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants