Skip to content
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

feat: nested collection support #7379

Merged
merged 23 commits into from
Feb 20, 2025
Merged

Conversation

nwidynski
Copy link
Contributor

Closes #7277 (comment)

As discussed, this change focuses only on the bare minimum to get nested collections to work.

✅ 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).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@LFDanLu
Copy link
Member

LFDanLu commented Nov 21, 2024

@nwidynski Heya, sorry about the delay, we were pretty busy with getting the release out. As mentioned in #7277 (comment) we are leaning towards supporting inputs in Gridlist first via something like #7360, which you had already noted doesn't solve the typeahead collision problem.

However, instead of making typeahead disable-able via a prop, we tossed around an idea of perhaps just doing some detection in the useTypeselect hook to see if the user was typing in an input and simply early return at that point. Any thoughts on that approach?

@nwidynski
Copy link
Contributor Author

@LFDanLu No worries about the timeline 👍

I suppose you were exploring that idea to lighten the burden on the developer? If so, I don't see why these necessarily have to exclude each other. Preventing type select only when focus is currently on an input, will still cause issues with nested collections. Was there other reasoning for prohibiting the exposure of disallowTypeAhead?

As mentioned (see comment), this PR focuses only on the essentials of supporting nested collections and can be seen as independent of #7360. Only the Document key and type select are things we have to fix upstream to implement our use-case. Everything else we proposed, including #7360, we can temporarily implement ourselves through a custom virtualizer.

On that note, any feedback from the team on #7376?

@LFDanLu
Copy link
Member

LFDanLu commented Nov 22, 2024

There was also a concern about exposing disallowTypeAhead since it may not be clear to a user when/when not to disable it. That being said, at a glance it doesn't appear in the grid spec so maybe not as core of an interaction pattern as previously thought. No feedback on #7376 just yet, I hope to take a look at it soon as soon as I get to a good place with the SearchableMenu/Autocomplete support myself.

@LFDanLu
Copy link
Member

LFDanLu commented Jan 23, 2025

Just wanted to give you an update, but the team tested this today and things looked pretty good. Only thing that we noticed was some of the examples in the Table docs here broke, I'll see if I can get a chance to dig soon. Still seeing about getting another pair of eyes on this. The team is also juggling a couple of other PRs alongside this one with widespread changes (usePress refactor/shadowDOM support) and is a bit worried about stacking them all into a single release. Ideally we'd give them all some time to bake before shipping, will keep you posted.

@nwidynski
Copy link
Contributor Author

nwidynski commented Jan 23, 2025

@LFDanLu Thanks for keeping me posted. The regression you noticed actually comes from a bug in the docs, which was uncovered by the improvement to Table. I fixed the same issue in Table.test.js already, where columns were not forwarded to the underlying Row, but missed it in the docs. Good catch regardless 👍

<Row id={id} {...otherProps}>

@snowystinger
Copy link
Member

Hey, just wanted to let you know we haven't forgotten about this. We're just moving a bit slowly right now as a few team members are on vacation. Thank you for your patience.

…prefix

# Conflicts:
#	packages/@react-aria/grid/src/useGridCell.ts
#	packages/react-aria-components/test/Table.test.js
@@ -218,7 +223,7 @@ function GridListInner<T extends object>({props, collection, gridListRef: ref}:
<div
{...filterDOMProps(props)}
{...renderProps}
{...mergeProps(gridProps, focusProps, droppableCollection?.collectionProps, emptyStatePropOverrides)}
{...mergeProps(gridProps, focusProps, droppableCollection?.collectionProps, emptyStatePropOverrides, {id})}
Copy link
Member

Choose a reason for hiding this comment

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

what happened here?

Copy link
Contributor Author

@nwidynski nwidynski Feb 15, 2025

Choose a reason for hiding this comment

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

This addresses two issues. The first is #7655, which we scheduled as a follow-up to this PR but has since landed. Second is that drag & drop hooks generate their own id without a defaultId, overriding any custom ids here.

Copy link
Member

Choose a reason for hiding this comment

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

hmm does the latter case still occur? I think mergeProps should merge the ids

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. @LFDanLu and I just agreed it would be better to hand the id down to gridlists call to useDroppableCollection to avoid implicitly relying on mergeProps #7379 (comment)

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 will just push that as follow-up once i get into the office tomorrow 👍

@devongovett
Copy link
Member

Hope you don't mind, I've pushed some changes to try to contain this within the selection package as much as possible so we don't need to handle this in each individual collection component. This way we generate a collection id in useSelectableCollection (attaching it to the actual Collection object via a WeakMap), and assign it to a data-collection attribute at the root and on each individual item. Then we can query for items using [data-collection="..."] to get all items in the collection, or [data-collection="..."][data-key="..."] to get a specific item.

…prefix

# Conflicts:
#	packages/@react-aria/selection/src/useSelectableCollection.ts
#	packages/@react-aria/selection/src/useSelectableItem.ts
#	packages/react-aria-components/test/Table.test.js
snowystinger
snowystinger previously approved these changes Feb 20, 2025
devongovett
devongovett previously approved these changes Feb 20, 2025
…prefix

# Conflicts:
#	packages/@react-aria/menu/src/useMenuItem.ts
#	packages/@react-aria/selection/src/useSelectableCollection.ts
#	packages/@react-aria/selection/src/useSelectableItem.ts
@devongovett devongovett dismissed stale reviews from snowystinger and themself via 2ce6172 February 20, 2025 23:25
@snowystinger snowystinger added this pull request to the merge queue Feb 20, 2025
Merged via the queue into adobe:main with commit 4f47a68 Feb 20, 2025
30 checks passed
@nwidynski nwidynski deleted the document_prefix branch February 21, 2025 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants