Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/react-aria-components/src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,11 @@ export interface CellRenderProps {
/**
* The unique id of the cell.
**/
id?: Key
id?: Key,
/**
* The index of the cell within its row.
*/
cellIndex: number
}

export interface CellProps extends RenderProps<CellRenderProps>, GlobalDOMAttributes<HTMLTableCellElement> {
Expand Down Expand Up @@ -1380,7 +1384,8 @@ export const Cell = /*#__PURE__*/ createLeafComponent(TableCellNode, (props: Cel
isPressed,
isHovered,
isSelected,
id: cell.key
id: cell.key,
cellIndex: cell.index
}
});

Expand Down
25 changes: 25 additions & 0 deletions packages/react-aria-components/test/Table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,31 @@ describe('Table', () => {
expect(cells[0]).toHaveTextContent('Foo (focused)');
});

it('should support cell index in render props', () => {
let {getAllByRole} = render(
<Table aria-label="Search results">
<TableHeader>
<Column isRowHeader>Name</Column>
<Column isRowHeader>Type</Column>
</TableHeader>
<TableBody>
<Row>
<Cell>
{({cellIndex}) => `cell index: ${cellIndex}`}
</Cell>
<Cell>
{({cellIndex}) => `cell index: ${cellIndex}`}
</Cell>
</Row>
</TableBody>
</Table>
);

let cells = getAllByRole('rowheader');
expect(cells[0]).toHaveTextContent('cell index: 0');
expect(cells[1]).toHaveTextContent('cell index: 1');
});

it('should support columnHeader typeahead', async () => {
let {getAllByRole} = render(
<Table aria-label="Files">
Expand Down