|
7 | 7 | Checkbox, |
8 | 8 | TableCell, |
9 | 9 | TableHead, |
| 10 | + TableRow, |
10 | 11 | TableSortLabel, |
11 | 12 | } from '@mui/material'; |
12 | 13 |
|
@@ -43,63 +44,68 @@ export const TableHeader = <T extends object>({ |
43 | 44 | }: TableHeaderProps<T>) => { |
44 | 45 | return ( |
45 | 46 | <TableHead sx={{ borderCollapse: 'collapse' }}> |
46 | | - {onSelectAllClick && ( |
47 | | - <TableCell data-table="table_cell__sticky_header" padding="checkbox"> |
48 | | - <Checkbox |
49 | | - color="primary" |
50 | | - indeterminate={checkedState === 'some'} |
51 | | - checked={ |
52 | | - (rowCount > 0 && numSelected === rowCount) || |
53 | | - checkedState === 'all' |
54 | | - } |
55 | | - onChange={() => { |
56 | | - const state = |
57 | | - checkedState === 'some' |
58 | | - ? 'none' |
59 | | - : checkedState === 'all' |
| 47 | + <TableRow> |
| 48 | + {onSelectAllClick && ( |
| 49 | + <TableCell data-table="table_cell__sticky_header" padding="checkbox"> |
| 50 | + <Checkbox |
| 51 | + color="primary" |
| 52 | + indeterminate={checkedState === 'some'} |
| 53 | + checked={ |
| 54 | + (rowCount > 0 && numSelected === rowCount) || |
| 55 | + checkedState === 'all' |
| 56 | + } |
| 57 | + onChange={() => { |
| 58 | + const state = |
| 59 | + checkedState === 'some' |
60 | 60 | ? 'none' |
61 | | - : 'all'; |
62 | | - const clientData = state === 'all' ? data : undefined; |
63 | | - onSelectAllClick?.(isServerSide ? undefined : clientData, state); |
64 | | - }} |
65 | | - inputProps={{ |
66 | | - 'aria-label': 'select all rows', |
67 | | - }} |
68 | | - /> |
69 | | - </TableCell> |
70 | | - )} |
71 | | - {columns.map( |
72 | | - (column, index) => |
73 | | - column.selected && ( |
74 | | - <TableCell |
75 | | - key={`${column.label}_${index}`} |
76 | | - align="left" |
77 | | - sortDirection={orderBy === column.key ? order : false} |
78 | | - sx={{ whiteSpace: 'nowrap', border: 'none' }} |
79 | | - > |
80 | | - {column.sortable ? ( |
81 | | - <TableSortLabel |
82 | | - active={orderBy === column.key} |
83 | | - direction={orderBy === column.key ? order : 'asc'} |
84 | | - onClick={(event) => { |
85 | | - onRequestSort(event, column); |
86 | | - }} |
87 | | - > |
88 | | - {column.label ?? column.title} |
89 | | - {orderBy === column.key ? ( |
90 | | - <Box component="span" sx={visuallyHidden}> |
91 | | - {order === 'desc' |
92 | | - ? 'sorted descending' |
93 | | - : 'sorted ascending'} |
94 | | - </Box> |
95 | | - ) : null} |
96 | | - </TableSortLabel> |
97 | | - ) : ( |
98 | | - (column.label ?? column.title) |
99 | | - )} |
100 | | - </TableCell> |
101 | | - ), |
102 | | - )} |
| 61 | + : checkedState === 'all' |
| 62 | + ? 'none' |
| 63 | + : 'all'; |
| 64 | + const clientData = state === 'all' ? data : undefined; |
| 65 | + onSelectAllClick?.( |
| 66 | + isServerSide ? undefined : clientData, |
| 67 | + state, |
| 68 | + ); |
| 69 | + }} |
| 70 | + inputProps={{ |
| 71 | + 'aria-label': 'select all rows', |
| 72 | + }} |
| 73 | + /> |
| 74 | + </TableCell> |
| 75 | + )} |
| 76 | + {columns.map( |
| 77 | + (column, index) => |
| 78 | + column.selected && ( |
| 79 | + <TableCell |
| 80 | + key={`${column.label}_${index}`} |
| 81 | + align="left" |
| 82 | + sortDirection={orderBy === column.key ? order : false} |
| 83 | + sx={{ whiteSpace: 'nowrap', border: 'none' }} |
| 84 | + > |
| 85 | + {column.sortable ? ( |
| 86 | + <TableSortLabel |
| 87 | + active={orderBy === column.key} |
| 88 | + direction={orderBy === column.key ? order : 'asc'} |
| 89 | + onClick={(event) => { |
| 90 | + onRequestSort(event, column); |
| 91 | + }} |
| 92 | + > |
| 93 | + {column.label ?? column.title} |
| 94 | + {orderBy === column.key ? ( |
| 95 | + <Box component="span" sx={visuallyHidden}> |
| 96 | + {order === 'desc' |
| 97 | + ? 'sorted descending' |
| 98 | + : 'sorted ascending'} |
| 99 | + </Box> |
| 100 | + ) : null} |
| 101 | + </TableSortLabel> |
| 102 | + ) : ( |
| 103 | + (column.label ?? column.title) |
| 104 | + )} |
| 105 | + </TableCell> |
| 106 | + ), |
| 107 | + )} |
| 108 | + </TableRow> |
103 | 109 | </TableHead> |
104 | 110 | ); |
105 | 111 | }; |
0 commit comments