Skip to content

feat: add maxSpace option to @react-stately/layout GridLayout #8654

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

Conversation

e-krebs
Copy link
Contributor

@e-krebs e-krebs commented Jul 30, 2025

Closes #8655

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
    • I added updated an existing storybook with using that option
    • I didn't find existing test for this file
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
    • from what I can see, running docs locally automatically updated them, so I guess nothing more is necessary?
  • Looked at the Accessibility Practices for this feature - Aria Practices
    • not applicable here?

📝 Test Instructions:

Run the storybook (locally)
Under "React Aria Components > GridList > Virtualized Grid List Grid"

before (without maxSpace) after (with maxSpace: 5)
image image

you can also test for more complex combination by modifying the layoutOptions.
For example with layoutOptions:

{
  minItemSize: new Size(40, 40),
  maxItemSize: new Size(65, 40),
  maxColumns: 3
}
before (without maxSpace) after (with maxSpace: 5)
image image

🧢 Your Project:

Algolia Visual Editor is available in the Algolia Dashboard & allows to create Rules to curate results for specific queries.
It makes use of Drag & Drop capabilities to allow to "pin" records to specific position (see example around 1min20s in this video)
we're currently in the process of migrating our existing drag & drop library (and virtualizer) to use react-aria-components.
In order to be able to consistently render grids of records across many pages in the Algolia Dashboard, we need to have a fixed gap between grid items. maxSpace will unlock this possibility without having to resort to artificially reduce the Virtualizer width with additional pre-computations

@e-krebs e-krebs marked this pull request as ready for review July 30, 2025 13:58
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me, sounds like a good idea to add to other applicable layouts (Waterfall). Not a call to action though, we can focus on just GridLayout for this PR.

Comment on lines 39 to 43
/**
* The maximum allowed horizontal space between items.
* @default Infinity
*/
maxSpace?: number,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this perhaps mirror minSpace by also determining the maximum vertical spacing between the items in the Grid?

Copy link
Contributor Author

@e-krebs e-krebs Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it (and happy to do it), but currently minSpace height value is effectively used as the vertical spacing value (not minimum nor maximum), so I wouldn't know what to do with the added maxSpace.height

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it certainly does feel a bit silly since the vertical spacing is always determined by the user unlike the horizontal spacing which depends on the item size/container width etc. Off the top of my head, I'd imagine we either change the name of maxSpace to reflect that it only applies for the horizontal spacing OR we keep the name and have it take it take a Size for consistency.

Leaning towards the first one personally if only to avoid having to do Math.min(maxSpace.height, minSpace.height) (again, silly because the user provides both)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the parameter maxHorizontalSize

@LFDanLu
Copy link
Member

LFDanLu commented Jul 30, 2025

Also, would you mind signing the CLA? See the CI check below

@e-krebs
Copy link
Contributor Author

e-krebs commented Jul 30, 2025

Also, would you mind signing the CLA? See the CI check below

Yep, I'm on it with legal on my side 😉

@e-krebs e-krebs requested a review from LFDanLu August 6, 2025 08:26
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for signing the CLA! Things look good to me, will see about getting another pair of eyes on this

Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the thorough description!

@snowystinger snowystinger added this pull request to the merge queue Aug 6, 2025
Merged via the queue into adobe:main with commit 2d44556 Aug 6, 2025
32 checks passed
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.

Allow @react-stately/layout GridLayout to configure maxSpace
4 participants