Skip to content

Commit 1253bf3

Browse files
committed
add tests
1 parent bb23bff commit 1253bf3

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,11 @@ export interface CellRenderProps {
13211321
/**
13221322
* The unique id of the cell.
13231323
**/
1324-
id?: Key
1324+
id?: Key,
1325+
/**
1326+
* The index of the cell within its row.
1327+
*/
1328+
cellIndex: number
13251329
}
13261330

13271331
export interface CellProps extends RenderProps<CellRenderProps>, GlobalDOMAttributes<HTMLTableCellElement> {

packages/react-aria-components/test/Table.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,31 @@ describe('Table', () => {
858858
expect(cells[0]).toHaveTextContent('Foo (focused)');
859859
});
860860

861+
it('should support cell index in render props', () => {
862+
let {getAllByRole} = render(
863+
<Table aria-label="Search results">
864+
<TableHeader>
865+
<Column isRowHeader>Name</Column>
866+
<Column isRowHeader>Type</Column>
867+
</TableHeader>
868+
<TableBody>
869+
<Row>
870+
<Cell>
871+
{({cellIndex}) => `cell index: ${cellIndex}`}
872+
</Cell>
873+
<Cell>
874+
{({cellIndex}) => `cell index: ${cellIndex}`}
875+
</Cell>
876+
</Row>
877+
</TableBody>
878+
</Table>
879+
);
880+
881+
let cells = getAllByRole('rowheader');
882+
expect(cells[0]).toHaveTextContent('cell index: 0');
883+
expect(cells[1]).toHaveTextContent('cell index: 1');
884+
});
885+
861886
it('should support columnHeader typeahead', async () => {
862887
let {getAllByRole} = render(
863888
<Table aria-label="Files">

0 commit comments

Comments
 (0)