Skip to content

fix: Table column updating #8211

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
merged 10 commits into from
May 10, 2025
Merged

fix: Table column updating #8211

merged 10 commits into from
May 10, 2025

Conversation

snowystinger
Copy link
Member

Closes #8127, #7345

Combination of examples and docs and some fixes to Document. Some of the changes were borrowed from @LFDanLu 's PR https://github.com/adobe/react-spectrum/pull/7938/files

✅ 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:

@@ -1208,6 +1208,75 @@ function Example() {
}
```

## Dependencies
Copy link
Member Author

Choose a reason for hiding this comment

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

name title of section?

Use the same strategies for reducing unnecessary invalidations as you would with any other hook.

This prop is an array of dependencies that will trigger a cache invalidation within the collection. It should follow the same rules as React various hooks with dependencies arrays.
> The list of dependencies must have a constant number of items and be written inline like `[dep1, dep2, dep3]`.
Copy link
Member Author

@snowystinger snowystinger May 9, 2025

Choose a reason for hiding this comment

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

link to React docs? I don't know if we follow exactly the same algorithm for comparing

Copy link
Member

Choose a reason for hiding this comment

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

We pass the dependencies directly to useMemo internally :)

Comment on lines 148 to 154
<TableBody items={items} dependencies={[cols]}>
{item => (
<Row id={item.id} columns={cols} dependencies={[cols]}>
{(col) => {
return <Cell>{item[col.id]}</Cell>;
}}
</Row>
Copy link
Member Author

Choose a reason for hiding this comment

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

this example isn't working for some reason??

Comment on lines 148 to 154
<TableBody items={items} dependencies={[cols]}>
{item => (
<Row id={item.id} columns={cols} dependencies={[cols]}>
{(col) => {
return <Cell>{item[col.id]}</Cell>;
}}
</Row>
Copy link
Member Author

Choose a reason for hiding this comment

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

this example isn't working for some reason??

@rspbot
Copy link

rspbot commented May 9, 2025



if (this._minInvalidChildIndex === child && child.previousSibling) {
this.invalidateChildIndices(child.previousSibling);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it move to the next sibling? After removing a child, the next sibling will now have a new index. The previous sibling won't change. Also what happens if you remove the first child?

Copy link
Member

Choose a reason for hiding this comment

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

actually I see I already had that below. I think we can just set minInvalidChildIndex to null here.

some of this will be added back in daniel's PR but was not important for this fix
@devongovett
Copy link
Member

Merged the dependencies example in Table docs into the Content section, which covers dynamic collections. Added checkbox group to show/hide columns, and button to add rows.

@rspbot
Copy link

rspbot commented May 9, 2025

made a separate story so it isn't included in the docs
@rspbot
Copy link

rspbot commented May 9, 2025

LFDanLu
LFDanLu previously approved these changes May 9, 2025
devongovett
devongovett previously approved these changes May 9, 2025
…umn-updating

# Conflicts:
#	packages/@react-aria/collections/src/Document.ts
@devongovett devongovett dismissed stale reviews from LFDanLu and themself via e9eb1c1 May 9, 2025 23:59
@devongovett devongovett enabled auto-merge May 10, 2025 00:03
@rspbot
Copy link

rspbot commented May 10, 2025

@rspbot
Copy link

rspbot commented May 10, 2025

## API Changes

@react-spectrum/s2

/@react-spectrum/s2:TableBody

 TableBody <T extends {}> {
   children?: ReactNode | (T) => ReactNode
+  dependencies?: ReadonlyArray<any>
   items?: Iterable<T>
   renderEmptyState?: (TableBodyRenderProps) => ReactNode
 }

/@react-spectrum/s2:Row

 Row <T extends {}> {
   children?: ReactNode | (T) => ReactElement
   columns?: Iterable<T>
+  dependencies?: ReadonlyArray<any>
   id?: Key
   textValue?: string
 }

/@react-spectrum/s2:TableBodyProps

 TableBodyProps <T> {
   children?: ReactNode | (T) => ReactNode
+  dependencies?: ReadonlyArray<any>
   items?: Iterable<T>
   renderEmptyState?: (TableBodyRenderProps) => ReactNode
 }

/@react-spectrum/s2:RowProps

 RowProps <T> {
   children?: ReactNode | (T) => ReactElement
   columns?: Iterable<T>
+  dependencies?: ReadonlyArray<any>
   id?: Key
   textValue?: string
 }

@devongovett devongovett added this pull request to the merge queue May 10, 2025
Merged via the queue into main with commit 1390063 May 10, 2025
30 checks passed
@devongovett devongovett deleted the table-column-updating branch May 10, 2025 00:19
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.

Unable to conditionally render Table Columns and Cells in [email protected]
4 participants