Skip to content

Commit

Permalink
fix: correctly handle disabled toolbar with top content
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanl-dropit committed Jan 9, 2025
1 parent a071896 commit 238764e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const MRT_TableHead = <TData extends MRT_RowData>({
options: {
enableStickyHeader,
enableTopContent,
enableTopToolbar,
layoutMode,
muiTableHeadProps,
positionToolbarAlertBanner,
Expand Down Expand Up @@ -57,7 +58,7 @@ export const MRT_TableHead = <TData extends MRT_RowData>({
top:
stickyHeader && layoutMode?.startsWith('grid')
? 0
: enableStickyHeader && enableTopContent
: enableStickyHeader && enableTopContent && enableTopToolbar
? getCommonToolbarStyles({ table, theme }).minHeight
: undefined,
zIndex: stickyHeader ? 2 : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const MRT_TopContent = <TData extends MRT_RowData>({
table,
}: MRT_TopContentProps<TData>) => {
const {
options: { renderTopContent },
options: { renderTopContent, enableTopToolbar },
} = table;
return (
<>
Expand All @@ -23,7 +23,7 @@ export const MRT_TopContent = <TData extends MRT_RowData>({
>
{parseFromValuesOrFunc(renderTopContent, { table })}
</Box>
<MRT_TopToolbar table={table} />
{enableTopToolbar && <MRT_TopToolbar table={table} />}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const data = [...Array(88)].map(() => ({
state: faker.location.state(),
}));

export const TopContentWithStaticHeader = () => (
export const TopContentWithStaticHeaderDefault = () => (
<MaterialReactTable
columns={columns}
data={data}
Expand Down Expand Up @@ -97,3 +97,22 @@ export const TopContentWithStickyHeaderShorterTable = () => (
)}
/>
);

export const TopContentWithHiddenTopToolbar = () => (
<MaterialReactTable
columns={columns}
data={data}
initialState={{ pagination: { pageIndex: 0, pageSize: 25 } }}
muiTableContainerProps={{ sx: { maxHeight: 400 } }}
enableStickyHeader
enableTopToolbar={false}
enableTopContent={true}
renderTopContent={({ table }) => (
<Paper elevation={3} sx={{ padding: '0.5rem', margin: '0.5rem' }}>
<h2 style={{ margin: '2rem', textAlign: 'center' }}>
Total rows: {table.getRowCount()}
</h2>
</Paper>
)}
/>
);

0 comments on commit 238764e

Please sign in to comment.