Skip to content

Commit 04e99d2

Browse files
Merge pull request #209 from balena-io-modules/fix-thead-error
RJST: Fix nested `th` and `thead` console warning
2 parents 9fd1935 + bf8bca2 commit 04e99d2

File tree

1 file changed

+62
-56
lines changed

1 file changed

+62
-56
lines changed

src/components/RJST/components/Table/TableHeader.tsx

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Checkbox,
88
TableCell,
99
TableHead,
10+
TableRow,
1011
TableSortLabel,
1112
} from '@mui/material';
1213

@@ -43,63 +44,68 @@ export const TableHeader = <T extends object>({
4344
}: TableHeaderProps<T>) => {
4445
return (
4546
<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'
6060
? '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>
103109
</TableHead>
104110
);
105111
};

0 commit comments

Comments
 (0)