Skip to content

fix: TableView height collapse when no fixed height given for empty a…#10321

Draft
rima10 wants to merge 1 commit into
adobe:mainfrom
rima10:main
Draft

fix: TableView height collapse when no fixed height given for empty a…#10321
rima10 wants to merge 1 commit into
adobe:mainfrom
rima10:main

Conversation

@rima10

@rima10 rima10 commented Jul 12, 2026

Copy link
Copy Markdown

Issue

Closes #10235

Summary

Fixes TableView height collapse when no explicit height is provided for empty and loading states. The table now auto-sizes to show column headers and empty state content without requiring a fixed height container.

Root Cause

The S2TableLayout was deriving the empty/loading body's Rect height from this.virtualizer!.size.height, creating a circular dependency:

  • Empty table asks "how tall should I be?"
  • Answer: "as tall as I currently measure on screen"
  • Browser measures: "as tall as your content says"
  • No explicit height → settles at 0px
  • Headers and empty state collapse

Solution

Moved empty-state rendering outside the size-locked virtualizer box to a sibling rowgroup that sizes itself by actual content:

Changes Made:

packages/react-aria-components/src/Table.tsx

  • Created renderTableEmptyState() helper to factor empty-state row/cell markup
  • Made TableBody's emptyState conditional on !isVirtualized
  • Added virtualized empty-state rowgroup sibling in TableInner as JSX sibling of CollectionRoot
  • Preserves existing a11y/test contract via second role="rowgroup" with data-empty="true"

packages/@react-spectrum/s2/src/TableView.tsx

  • Changed .table style to display: flex; flex-direction: column for proper flex layout
  • Removed circular width override in buildCollection()
  • Fixed buildRowGroup() to reset height for empty/loading case from base layout's circular value to actual computed height
  • Removed unused Rect import

packages/@react-spectrum/s2/stories/TableView.stories.tsx

  • Updated EmptyState story: removed fixed height: 320 → allows auto-size
  • Added EmptyStateNoHeight story: no explicit height at all, validates the fix

Testing

  • Virtualized empty-state test suite passes
  • Loading state spinner still renders correctly
  • Column headers now visible without explicit height
  • Table properly auto-sizes to content while maintaining virtualization for large datasets

Behavior Change

  • Before: Empty/loading tables collapsed to ~0px height without explicit styles={{ height: N }}
  • After: Tables auto-size to fit headers + empty state content, headers always visible

✅ Checklist

📝 Test Instructions

Storybook:

  1. Open packages/@react-spectrum/s2/stories/TableView.stories.tsx
  2. View EmptyStateNoHeight story (no explicit height)
  3. Verify column headers are visible
  4. Verify empty state message is centered and visible
  5. Compare with EmptyState story (has explicit width only)

Manual Testing:

// This now works correctly without height prop:
<TableView aria-label="No height" styles={style({width: 320})}>
  <TableHeader columns={columns}>...</TableHeader>
  <TableBody items={[]} renderEmptyState={renderEmptyState} />
</TableView>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TableView Empty State Not Rendered When No Height Is Specified

1 participant