MCPcopy Index your code
hub / github.com/adobe/react-spectrum / Table

Function Table

packages/react-aria/test/table/useTable.test.tsx:47–98  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

45];
46// copied in so as to put onAction into the TableRow
47function Table(props) {
48 let state = useTableState({
49 ...props,
50 showSelectionCheckboxes: props.selectionMode === 'multiple'
51 });
52 let ref = useRef<HTMLTableElement | null>(null);
53 let bodyRef = useRef<HTMLElement | null>(null);
54 let {collection} = state;
55 let {gridProps} = useTable(
56 {
57 ...props,
58 onRowAction: props.onAction,
59 scrollRef: bodyRef
60 },
61 state,
62 ref
63 );
64
65 return (
66 <table {...gridProps} ref={ref} style={{borderCollapse: 'collapse'}}>
67 <TableRowGroup type="thead" style={{borderBottom: '2px solid gray', display: 'block'}}>
68 {collection.headerRows.map(headerRow => (
69 <TableHeaderRow key={headerRow.key} item={headerRow} state={state}>
70 {[...state.collection.getChildren!(headerRow.key)].map(column =>
71 column.props.isSelectionCell ? (
72 <TableSelectAllCell key={column.key} column={column} state={state} />
73 ) : (
74 <TableColumnHeader key={column.key} column={column} state={state} />
75 )
76 )}
77 </TableHeaderRow>
78 ))}
79 </TableRowGroup>
80 <TableRowGroup
81 ref={bodyRef}
82 type="tbody"
83 style={{display: 'block', overflow: 'auto', maxHeight: '200px'}}>
84 {[...collection].map(row => (
85 <TableRow key={row.key} item={row} state={state}>
86 {[...state.collection.getChildren!(row.key)].map(cell =>
87 cell.props.isSelectionCell ? (
88 <TableCheckboxCell key={cell.key} cell={cell} state={state} />
89 ) : (
90 <TableCell key={cell.key} cell={cell} state={state} />
91 )
92 )}
93 </TableRow>
94 ))}
95 </TableRowGroup>
96 </table>
97 );
98}
99// I'd use tree.getByRole(role, {name: text}) here, but it's unbearably slow.
100let getCell = (tree, text) => {
101 // Find by text, then go up to the element with the cell role.

Callers

nothing calls this directly

Calls 2

useTableStateFunction · 0.90
useTableFunction · 0.90

Tested by

no test coverage detected