diff --git a/packages/react-aria-components/stories/Table.stories.tsx b/packages/react-aria-components/stories/Table.stories.tsx index 03f353256db..5409b9d9d5e 100644 --- a/packages/react-aria-components/stories/Table.stories.tsx +++ b/packages/react-aria-components/stories/Table.stories.tsx @@ -1152,6 +1152,73 @@ export const OnLoadMoreTableVirtualizedResizeWrapperStory: StoryObj { + let list = useAsyncList({ + async load({signal, cursor}) { + if (cursor) { + cursor = cursor.replace(/^http:\/\//i, 'https://'); + await new Promise(resolve => setTimeout(resolve, args.delay)); + } + let res = await fetch(cursor || 'https://swapi.py4e.com/api/people/?search=', {signal}); + let json = await res.json(); + return { + items: json.results, + cursor: json.next + }; + } + }); + + return ( +
+ + + + Name + Height + Mass + Birth Year + + renderEmptyLoader({isLoading: list.loadingState === 'loading'})}> + + {(item) => ( + + {item.name} + {item.height} + {item.mass} + {item.birth_year} + + )} + + + + + +
+
+
+ ); +}; + +export const VirtualizedTableLoaderWidthTestStory: StoryObj = { + render: VirtualizedTableLoaderWidthTest, + name: 'virtualized table, loader dynamic width', + args: {delay: 10000}, + parameters: { + description: { + data: 'resizing the table should also resize the loader element width' + } + } +}; + interface Launch { id: number, mission_name: string, diff --git a/packages/react-stately/src/layout/TableLayout.ts b/packages/react-stately/src/layout/TableLayout.ts index a9fc643b8ad..dca6d1fdfba 100644 --- a/packages/react-stately/src/layout/TableLayout.ts +++ b/packages/react-stately/src/layout/TableLayout.ts @@ -361,6 +361,17 @@ export class TableLayout exten }; } + protected buildLoader(node: GridNode, x: number, y: number): LayoutNode { + let layoutNode = super.buildLoader(node, x, y); + let collection = this.virtualizer!.collection as TableCollection; + + // use the same approach as buildRow to get the proper width of the loader, otherwise + // we get a outdated loader width + layoutNode.layoutInfo.rect.width = this.layoutNodes.get(collection.head?.key ?? 'header')!.layoutInfo.rect.width; + layoutNode.validRect = layoutNode.layoutInfo.rect.intersection(this.requestedRect); + return layoutNode; + } + protected buildNode(node: GridNode, x: number, y: number): LayoutNode { switch (node.type) { case 'headerrow':