@cutting/material-react-table 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -4
- package/dist/index.d.ts +186 -524
- package/dist/index.js +323 -342
- package/dist/index.js.map +1 -1
- package/locales/ar/index.mjs +1 -2
- package/locales/az/index.mjs +1 -2
- package/locales/bg/index.mjs +1 -2
- package/locales/cs/index.mjs +1 -2
- package/locales/da/index.mjs +1 -2
- package/locales/de/index.mjs +1 -2
- package/locales/el/index.mjs +1 -2
- package/locales/en/index.mjs +1 -2
- package/locales/es/index.mjs +1 -2
- package/locales/et/index.mjs +1 -2
- package/locales/fa/index.mjs +1 -2
- package/locales/fi/index.mjs +1 -2
- package/locales/fr/index.mjs +1 -2
- package/locales/he/index.mjs +1 -2
- package/locales/hr/index.mjs +1 -2
- package/locales/hu/index.mjs +1 -2
- package/locales/hy/index.mjs +1 -2
- package/locales/id/index.mjs +1 -2
- package/locales/it/index.mjs +1 -2
- package/locales/ja/index.mjs +1 -2
- package/locales/ko/index.mjs +1 -2
- package/locales/nl/index.mjs +1 -2
- package/locales/no/index.mjs +1 -2
- package/locales/np/index.mjs +1 -2
- package/locales/pl/index.mjs +1 -2
- package/locales/pt/index.mjs +1 -2
- package/locales/pt-BR/index.mjs +1 -2
- package/locales/ro/index.mjs +1 -2
- package/locales/ru/index.mjs +1 -2
- package/locales/sk/index.mjs +1 -2
- package/locales/sr-Cyrl-RS/index.mjs +1 -2
- package/locales/sr-Latn-RS/index.mjs +1 -2
- package/locales/sv/index.mjs +1 -2
- package/locales/tr/index.mjs +1 -2
- package/locales/uk/index.mjs +1 -2
- package/locales/vi/index.mjs +1 -2
- package/locales/zh-Hans/index.mjs +1 -2
- package/locales/zh-Hant/index.mjs +1 -2
- package/package.json +19 -27
- package/src/MaterialReactTable.smoke.test.tsx +3 -9
- package/src/components/MaterialReactTable.tsx +13 -21
- package/src/components/body/MRT_TableBody.tsx +67 -82
- package/src/components/body/MRT_TableBodyCell.tsx +38 -80
- package/src/components/body/MRT_TableBodyCellValue.tsx +5 -14
- package/src/components/body/MRT_TableBodyRow.tsx +55 -102
- package/src/components/body/MRT_TableBodyRowGrabHandle.test.tsx +2 -6
- package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +4 -9
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +8 -14
- package/src/components/body/MRT_TableDetailPanel.test.tsx +3 -9
- package/src/components/body/MRT_TableDetailPanel.tsx +8 -14
- package/src/components/buttons/MRT_ColumnPinningButtons.test.tsx +6 -16
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +6 -12
- package/src/components/buttons/MRT_CopyButton.tsx +7 -15
- package/src/components/buttons/MRT_EditActionButtons.test.tsx +2 -6
- package/src/components/buttons/MRT_EditActionButtons.tsx +15 -37
- package/src/components/buttons/MRT_ExpandAllButton.tsx +8 -16
- package/src/components/buttons/MRT_ExpandButton.tsx +9 -21
- package/src/components/buttons/MRT_GrabHandleButton.tsx +6 -10
- package/src/components/buttons/MRT_RowPinButton.tsx +8 -23
- package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +5 -18
- package/src/components/buttons/MRT_ToggleDensePaddingButton.test.tsx +4 -12
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +4 -11
- package/src/components/buttons/MRT_ToggleFiltersButton.test.tsx +4 -13
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +3 -5
- package/src/components/buttons/MRT_ToggleFullScreenButton.test.tsx +3 -11
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +4 -9
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +3 -5
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +7 -15
- package/src/components/footer/MRT_TableFooter.tsx +9 -16
- package/src/components/footer/MRT_TableFooterCell.tsx +9 -32
- package/src/components/footer/MRT_TableFooterRow.tsx +18 -32
- package/src/components/head/MRT_TableHead.tsx +8 -18
- package/src/components/head/MRT_TableHeadCell.tsx +46 -100
- package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +10 -30
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +4 -15
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +20 -54
- package/src/components/head/MRT_TableHeadCellGrabHandle.test.tsx +5 -19
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +9 -38
- package/src/components/head/MRT_TableHeadCellResizeHandle.test.tsx +3 -13
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +10 -24
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +10 -26
- package/src/components/head/MRT_TableHeadRow.tsx +24 -36
- package/src/components/inputs/MRT_EditCellTextField.test.tsx +2 -9
- package/src/components/inputs/MRT_EditCellTextField.tsx +9 -28
- package/src/components/inputs/MRT_FilterCheckbox.tsx +9 -23
- package/src/components/inputs/MRT_FilterRangeFields.tsx +6 -15
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +24 -32
- package/src/components/inputs/MRT_FilterTextField.test.tsx +72 -14
- package/src/components/inputs/MRT_FilterTextField.tsx +77 -138
- package/src/components/inputs/MRT_GlobalFilterTextField.tsx +10 -32
- package/src/components/inputs/MRT_SelectCheckbox.test.tsx +4 -11
- package/src/components/inputs/MRT_SelectCheckbox.tsx +17 -36
- package/src/components/menus/MRT_ActionMenuItem.tsx +6 -15
- package/src/components/menus/MRT_CellActionMenu.tsx +6 -9
- package/src/components/menus/MRT_ColumnActionMenu.tsx +22 -57
- package/src/components/menus/MRT_FilterOptionMenu.tsx +38 -65
- package/src/components/menus/MRT_RowActionMenu.tsx +33 -22
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +29 -65
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.test.tsx +43 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +14 -50
- package/src/components/modals/MRT_EditRowModal.test.tsx +5 -21
- package/src/components/modals/MRT_EditRowModal.tsx +8 -26
- package/src/components/table/MRT_Table.tsx +12 -20
- package/src/components/table/MRT_TableContainer.test.tsx +147 -0
- package/src/components/table/MRT_TableContainer.tsx +33 -37
- package/src/components/table/MRT_TableLoadingOverlay.tsx +3 -5
- package/src/components/table/MRT_TablePaper.tsx +7 -14
- package/src/components/toolbar/MRT_BottomToolbar.tsx +11 -23
- package/src/components/toolbar/MRT_LinearProgressBar.tsx +4 -11
- package/src/components/toolbar/MRT_TablePagination.tsx +33 -40
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +21 -50
- package/src/components/toolbar/MRT_ToolbarDropZone.test.tsx +26 -10
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +23 -21
- package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +11 -21
- package/src/components/toolbar/MRT_TopToolbar.tsx +12 -28
- package/src/fns/aggregationFns.test.tsx +1 -3
- package/src/fns/filterFns.test.tsx +8 -37
- package/src/fns/filterFns.ts +71 -96
- package/src/fns/sortingFns.test.tsx +5 -21
- package/src/fns/sortingFns.ts +10 -14
- package/src/fns/tableFeatures.test.tsx +6 -29
- package/src/fns/tableFeatures.ts +5 -4
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +2 -11
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +2 -10
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +8 -17
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +3 -8
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +2 -8
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +3 -13
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +1 -5
- package/src/hooks/useMRT_ColumnVirtualizer.ts +28 -49
- package/src/hooks/useMRT_Effects.test.tsx +114 -0
- package/src/hooks/useMRT_Effects.ts +26 -27
- package/src/hooks/useMRT_RowVirtualizer.ts +18 -33
- package/src/hooks/useMRT_Rows.ts +3 -42
- package/src/hooks/useMRT_TableInstance.ts +63 -129
- package/src/hooks/useMRT_TableOptions.ts +15 -29
- package/src/hooks/useMaterialReactTable.ts +2 -7
- package/src/icons.ts +38 -1
- package/src/index.ts +0 -4
- package/src/locales/ar.ts +1 -2
- package/src/locales/az.ts +1 -2
- package/src/locales/bg.ts +1 -2
- package/src/locales/cs.ts +2 -4
- package/src/locales/da.ts +1 -2
- package/src/locales/de.ts +1 -2
- package/src/locales/el.ts +1 -2
- package/src/locales/en.ts +1 -2
- package/src/locales/es.ts +1 -2
- package/src/locales/et.ts +2 -4
- package/src/locales/fa.ts +1 -2
- package/src/locales/fi.ts +2 -4
- package/src/locales/fr.ts +1 -2
- package/src/locales/he.ts +1 -2
- package/src/locales/hr.ts +1 -2
- package/src/locales/hu.ts +1 -2
- package/src/locales/hy.ts +1 -2
- package/src/locales/id.ts +2 -4
- package/src/locales/it.ts +1 -2
- package/src/locales/ja.ts +1 -2
- package/src/locales/ko.ts +1 -2
- package/src/locales/nl.ts +1 -2
- package/src/locales/no.ts +2 -4
- package/src/locales/np.ts +2 -4
- package/src/locales/pl.ts +1 -2
- package/src/locales/pt-BR.ts +1 -2
- package/src/locales/pt.ts +1 -2
- package/src/locales/ro.ts +1 -2
- package/src/locales/ru.ts +1 -2
- package/src/locales/sk.ts +2 -4
- package/src/locales/sr-Cyrl-RS.ts +1 -2
- package/src/locales/sr-Latn-RS.ts +1 -2
- package/src/locales/sv.ts +1 -2
- package/src/locales/tr.ts +1 -2
- package/src/locales/uk.ts +1 -2
- package/src/locales/vi.ts +1 -2
- package/src/types.ts +156 -349
- package/src/utils/cell.utils.ts +30 -68
- package/src/utils/column.utils.ts +61 -49
- package/src/utils/displayColumn.utils.ts +16 -38
- package/src/utils/highlight.utils.ts +7 -11
- package/src/utils/row.utils.ts +40 -65
- package/src/utils/slotProps.utils.ts +1 -4
- package/src/utils/style.utils.ts +18 -46
- package/src/utils/tanstack.helpers.ts +10 -17
- package/src/utils/utils.ts +6 -10
- package/src/utils/virtualization.utils.ts +5 -9
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import { Box } from '@mui/material';
|
|
2
|
-
import { Button } from '@mui/material';
|
|
3
|
-
import { Divider } from '@mui/material';
|
|
4
|
-
import { Menu, type MenuProps } from '@mui/material';
|
|
1
|
+
import { Box, Button, Divider, Menu, type MenuProps } from '@mui/material';
|
|
5
2
|
import { useMemo, useState } from 'react';
|
|
6
3
|
|
|
7
|
-
import {
|
|
8
|
-
type MRT_Column,
|
|
9
|
-
type MRT_RowData,
|
|
10
|
-
type MRT_TableInstance,
|
|
11
|
-
type MRT_VisibilityState
|
|
12
|
-
} from '../../types';
|
|
4
|
+
import { type MRT_Column, type MRT_RowData, type MRT_TableInstance, type MRT_VisibilityState } from '../../types';
|
|
13
5
|
import { getDefaultColumnOrderIds } from '../../utils/displayColumn.utils';
|
|
14
6
|
import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
|
|
15
7
|
|
|
16
|
-
export interface MRT_ShowHideColumnsMenuProps<TData extends MRT_RowData>
|
|
17
|
-
extends Partial<MenuProps> {
|
|
8
|
+
export interface MRT_ShowHideColumnsMenuProps<TData extends MRT_RowData> extends Partial<MenuProps> {
|
|
18
9
|
anchorEl: HTMLElement | null;
|
|
19
10
|
isSubMenu?: boolean;
|
|
20
11
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
@@ -26,7 +17,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
|
|
|
26
17
|
setAnchorEl,
|
|
27
18
|
table,
|
|
28
19
|
...rest
|
|
29
|
-
}: MRT_ShowHideColumnsMenuProps<TData>) => {
|
|
20
|
+
}: MRT_ShowHideColumnsMenuProps<TData>): JSX.Element => {
|
|
30
21
|
const {
|
|
31
22
|
getAllColumns,
|
|
32
23
|
getAllLeafColumns,
|
|
@@ -45,61 +36,47 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
|
|
|
45
36
|
mrtTheme: { menuBackgroundColor },
|
|
46
37
|
},
|
|
47
38
|
} = table;
|
|
48
|
-
const { columnOrder,
|
|
39
|
+
const { columnOrder, density } = table.state;
|
|
49
40
|
|
|
50
41
|
const handleToggleAllColumns = (value?: boolean) => {
|
|
51
|
-
const updates =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}, {} as MRT_VisibilityState);
|
|
42
|
+
const updates = getAllLeafColumns()
|
|
43
|
+
.filter((column) => column.columnDef.enableHiding !== false)
|
|
44
|
+
.reduce((acc, column) => {
|
|
45
|
+
acc[column.id] = value ?? !column.getIsVisible();
|
|
46
|
+
return acc;
|
|
47
|
+
}, {} as MRT_VisibilityState);
|
|
58
48
|
|
|
59
49
|
table.setColumnVisibility((old) => ({ ...old, ...updates }));
|
|
60
50
|
};
|
|
61
51
|
|
|
52
|
+
const allTableColumns = getAllColumns();
|
|
53
|
+
const centerLeafColumns = getCenterLeafColumns();
|
|
54
|
+
const leftLeafColumns = getLeftLeafColumns();
|
|
55
|
+
const rightLeafColumns = getRightLeafColumns();
|
|
56
|
+
|
|
62
57
|
const allColumns = useMemo(() => {
|
|
63
|
-
const columns =
|
|
64
|
-
if (
|
|
65
|
-
columnOrder.length > 0 &&
|
|
66
|
-
!columns.some((col) => col.columnDef.columnDefType === 'group')
|
|
67
|
-
) {
|
|
58
|
+
const columns = allTableColumns;
|
|
59
|
+
if (columnOrder.length > 0 && !columns.some((col) => col.columnDef.columnDefType === 'group')) {
|
|
68
60
|
return [
|
|
69
|
-
...
|
|
70
|
-
...Array.from(new Set(columnOrder)).map((colId) =>
|
|
71
|
-
|
|
72
|
-
),
|
|
73
|
-
...getRightLeafColumns(),
|
|
61
|
+
...leftLeafColumns,
|
|
62
|
+
...Array.from(new Set(columnOrder)).map((colId) => centerLeafColumns.find((col) => col?.id === colId)),
|
|
63
|
+
...rightLeafColumns,
|
|
74
64
|
].filter(Boolean);
|
|
75
65
|
}
|
|
76
66
|
return columns;
|
|
77
|
-
}, [
|
|
78
|
-
columnOrder,
|
|
79
|
-
columnPinning,
|
|
80
|
-
getAllColumns(),
|
|
81
|
-
getCenterLeafColumns(),
|
|
82
|
-
getLeftLeafColumns(),
|
|
83
|
-
getRightLeafColumns(),
|
|
84
|
-
]) as MRT_Column<TData>[];
|
|
67
|
+
}, [allTableColumns, centerLeafColumns, columnOrder, leftLeafColumns, rightLeafColumns]) as MRT_Column<TData>[];
|
|
85
68
|
|
|
86
|
-
const isNestedColumns = allColumns.some(
|
|
87
|
-
(col) => col.columnDef.columnDefType === 'group',
|
|
88
|
-
);
|
|
69
|
+
const isNestedColumns = allColumns.some((col) => col.columnDef.columnDefType === 'group');
|
|
89
70
|
|
|
90
71
|
const hasColumnOrderChanged = useMemo(
|
|
91
72
|
() =>
|
|
92
73
|
columnOrder.length !== initialState.columnOrder.length ||
|
|
93
|
-
!columnOrder.every(
|
|
94
|
-
(column, index) => column === initialState.columnOrder[index],
|
|
95
|
-
),
|
|
74
|
+
!columnOrder.every((column, index) => column === initialState.columnOrder[index]),
|
|
96
75
|
|
|
97
76
|
[columnOrder, initialState.columnOrder],
|
|
98
77
|
);
|
|
99
78
|
|
|
100
|
-
const [hoveredColumn, setHoveredColumn] = useState<MRT_Column<TData> | null>(
|
|
101
|
-
null,
|
|
102
|
-
);
|
|
79
|
+
const [hoveredColumn, setHoveredColumn] = useState<MRT_Column<TData> | null>(null);
|
|
103
80
|
|
|
104
81
|
return (
|
|
105
82
|
<Menu
|
|
@@ -126,38 +103,25 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
|
|
|
126
103
|
}}
|
|
127
104
|
>
|
|
128
105
|
{enableHiding && (
|
|
129
|
-
<Button
|
|
130
|
-
disabled={!getIsSomeColumnsVisible()}
|
|
131
|
-
onClick={() => handleToggleAllColumns(false)}
|
|
132
|
-
>
|
|
106
|
+
<Button disabled={!getIsSomeColumnsVisible()} onClick={() => handleToggleAllColumns(false)}>
|
|
133
107
|
{localization.hideAll}
|
|
134
108
|
</Button>
|
|
135
109
|
)}
|
|
136
110
|
{enableColumnOrdering && (
|
|
137
111
|
<Button
|
|
138
112
|
disabled={!hasColumnOrderChanged}
|
|
139
|
-
onClick={() =>
|
|
140
|
-
table.setColumnOrder(
|
|
141
|
-
getDefaultColumnOrderIds(table.options, true),
|
|
142
|
-
)
|
|
143
|
-
}
|
|
113
|
+
onClick={() => table.setColumnOrder(getDefaultColumnOrderIds(table.options, true))}
|
|
144
114
|
>
|
|
145
115
|
{localization.resetOrder}
|
|
146
116
|
</Button>
|
|
147
117
|
)}
|
|
148
118
|
{enableColumnPinning && (
|
|
149
|
-
<Button
|
|
150
|
-
disabled={!getIsSomeColumnsPinned()}
|
|
151
|
-
onClick={() => table.resetColumnPinning(true)}
|
|
152
|
-
>
|
|
119
|
+
<Button disabled={!getIsSomeColumnsPinned()} onClick={() => table.resetColumnPinning(true)}>
|
|
153
120
|
{localization.unpinAll}
|
|
154
121
|
</Button>
|
|
155
122
|
)}
|
|
156
123
|
{enableHiding && (
|
|
157
|
-
<Button
|
|
158
|
-
disabled={getIsAllColumnsVisible()}
|
|
159
|
-
onClick={() => handleToggleAllColumns(true)}
|
|
160
|
-
>
|
|
124
|
+
<Button disabled={getIsAllColumnsVisible()} onClick={() => handleToggleAllColumns(true)}>
|
|
161
125
|
{localization.showAll}
|
|
162
126
|
</Button>
|
|
163
127
|
)}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { fireEvent, render, screen, within } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { describe, expect, test } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import { type MRT_ColumnDef } from '../../types';
|
|
6
|
+
import { MaterialReactTable } from '../MaterialReactTable';
|
|
7
|
+
|
|
8
|
+
interface Person {
|
|
9
|
+
city: string;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const data: Person[] = [{ city: 'Glasgow', name: 'Alice' }];
|
|
14
|
+
|
|
15
|
+
const columns: MRT_ColumnDef<Person>[] = [
|
|
16
|
+
{ accessorKey: 'name', header: 'Name' },
|
|
17
|
+
{ accessorKey: 'city', header: 'City' },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const headerOrder = (container: HTMLElement) =>
|
|
21
|
+
Array.from(container.querySelectorAll('thead th')).map((th) => th.textContent?.replace(/[^A-Za-z]/g, ''));
|
|
22
|
+
|
|
23
|
+
describe('show/hide columns menu', () => {
|
|
24
|
+
test('dragging a column onto another reorders the table columns', async () => {
|
|
25
|
+
const user = userEvent.setup();
|
|
26
|
+
const { container } = render(<MaterialReactTable columns={columns} data={data} enableColumnOrdering />);
|
|
27
|
+
|
|
28
|
+
await user.click(screen.getByRole('button', { name: 'Show/Hide columns' }));
|
|
29
|
+
|
|
30
|
+
const menu = screen.getByRole('menu');
|
|
31
|
+
const nameItem = within(menu).getByText('Name').closest('li') as HTMLElement;
|
|
32
|
+
const cityItem = within(menu).getByText('City').closest('li') as HTMLElement;
|
|
33
|
+
const nameHandle = within(nameItem).getByRole('button', { name: 'Move' });
|
|
34
|
+
|
|
35
|
+
fireEvent.dragStart(nameHandle, {
|
|
36
|
+
dataTransfer: { setDragImage: () => {} },
|
|
37
|
+
});
|
|
38
|
+
fireEvent.dragEnter(cityItem);
|
|
39
|
+
fireEvent.dragEnd(nameHandle);
|
|
40
|
+
|
|
41
|
+
expect(headerOrder(container)).toEqual(['City', 'Name']);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -1,30 +1,15 @@
|
|
|
1
|
-
import { Box } from '@mui/material';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Switch } from '@mui/material';
|
|
5
|
-
import { Tooltip } from '@mui/material';
|
|
6
|
-
import { Typography } from '@mui/material';
|
|
7
|
-
import {
|
|
8
|
-
type Dispatch,
|
|
9
|
-
type DragEvent,
|
|
10
|
-
type SetStateAction,
|
|
11
|
-
useRef,
|
|
12
|
-
useState,
|
|
13
|
-
} from 'react';
|
|
1
|
+
import { Box, FormControlLabel, MenuItem, type MenuItemProps, Switch, Tooltip, Typography } from '@mui/material';
|
|
2
|
+
import { type CSSObject } from '@mui/material/styles';
|
|
3
|
+
import { type Dispatch, type DragEvent, type SetStateAction, useRef, useState } from 'react';
|
|
14
4
|
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
type MRT_RowData,
|
|
18
|
-
type MRT_TableInstance,
|
|
19
|
-
} from '../../types';
|
|
20
|
-
import { reorderColumn } from '../../utils/column.utils';
|
|
5
|
+
import { type MRT_Column, type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
6
|
+
import { moveColumn } from '../../utils/column.utils';
|
|
21
7
|
import { getCommonTooltipProps } from '../../utils/style.utils';
|
|
22
8
|
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
23
9
|
import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
|
|
24
10
|
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
|
|
25
11
|
|
|
26
|
-
export interface MRT_ShowHideColumnsMenuItemsProps<TData extends MRT_RowData>
|
|
27
|
-
extends MenuItemProps {
|
|
12
|
+
export interface MRT_ShowHideColumnsMenuItemsProps<TData extends MRT_RowData> extends MenuItemProps {
|
|
28
13
|
allColumns: MRT_Column<TData>[];
|
|
29
14
|
column: MRT_Column<TData>;
|
|
30
15
|
hoveredColumn: MRT_Column<TData> | null;
|
|
@@ -41,7 +26,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
|
41
26
|
setHoveredColumn,
|
|
42
27
|
table,
|
|
43
28
|
...rest
|
|
44
|
-
}: MRT_ShowHideColumnsMenuItemsProps<TData>) => {
|
|
29
|
+
}: MRT_ShowHideColumnsMenuItemsProps<TData>): JSX.Element | null => {
|
|
45
30
|
const {
|
|
46
31
|
options: {
|
|
47
32
|
enableColumnOrdering,
|
|
@@ -50,10 +35,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
|
50
35
|
localization,
|
|
51
36
|
mrtTheme: { draggingBorderColor },
|
|
52
37
|
},
|
|
53
|
-
setColumnOrder,
|
|
54
|
-
setColumnPinning,
|
|
55
38
|
} = table;
|
|
56
|
-
const { columnOrder } = table.state;
|
|
57
39
|
const { columnDef } = column;
|
|
58
40
|
const { columnDefType } = columnDef;
|
|
59
41
|
|
|
@@ -69,7 +51,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
|
69
51
|
}
|
|
70
52
|
};
|
|
71
53
|
|
|
72
|
-
const menuItemRef = useRef<
|
|
54
|
+
const menuItemRef = useRef<HTMLLIElement>(null);
|
|
73
55
|
|
|
74
56
|
const [isDragging, setIsDragging] = useState(false);
|
|
75
57
|
|
|
@@ -86,16 +68,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
|
86
68
|
setIsDragging(false);
|
|
87
69
|
setHoveredColumn(null);
|
|
88
70
|
if (hoveredColumn) {
|
|
89
|
-
|
|
90
|
-
column,
|
|
91
|
-
hoveredColumn,
|
|
92
|
-
columnOrder,
|
|
93
|
-
);
|
|
94
|
-
setColumnOrder(reorderedColumns);
|
|
95
|
-
setColumnPinning(({ end = [], start = [] }) => ({
|
|
96
|
-
end: reorderedColumns.filter((header) => end.includes(header)),
|
|
97
|
-
start: reorderedColumns.filter((header) => start.includes(header)),
|
|
98
|
-
}));
|
|
71
|
+
moveColumn(table, column, hoveredColumn);
|
|
99
72
|
}
|
|
100
73
|
};
|
|
101
74
|
|
|
@@ -114,7 +87,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
|
114
87
|
<MenuItem
|
|
115
88
|
disableRipple
|
|
116
89
|
onDragEnter={handleDragEnter}
|
|
117
|
-
ref={menuItemRef
|
|
90
|
+
ref={menuItemRef}
|
|
118
91
|
{...rest}
|
|
119
92
|
sx={(theme) => ({
|
|
120
93
|
alignItems: 'center',
|
|
@@ -129,7 +102,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
|
129
102
|
outlineOffset: '-2px',
|
|
130
103
|
pl: `${(column.depth + 0.5) * 2}rem`,
|
|
131
104
|
py: '6px',
|
|
132
|
-
...(parseFromValuesOrFunc(rest?.sx, theme) as
|
|
105
|
+
...(parseFromValuesOrFunc(rest?.sx, theme) as CSSObject),
|
|
133
106
|
})}
|
|
134
107
|
>
|
|
135
108
|
<Box
|
|
@@ -143,11 +116,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
|
143
116
|
enableColumnOrdering &&
|
|
144
117
|
!isNestedColumns &&
|
|
145
118
|
(columnDef.enableColumnOrdering !== false ? (
|
|
146
|
-
<MRT_GrabHandleButton
|
|
147
|
-
onDragEnd={handleDragEnd}
|
|
148
|
-
onDragStart={handleDragStart}
|
|
149
|
-
table={table}
|
|
150
|
-
/>
|
|
119
|
+
<MRT_GrabHandleButton onDragEnd={handleDragEnd} onDragStart={handleDragStart} table={table} />
|
|
151
120
|
) : (
|
|
152
121
|
<Box sx={{ width: '28px' }} />
|
|
153
122
|
))}
|
|
@@ -161,10 +130,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
|
161
130
|
<FormControlLabel
|
|
162
131
|
checked={switchChecked}
|
|
163
132
|
control={
|
|
164
|
-
<Tooltip
|
|
165
|
-
{...getCommonTooltipProps()}
|
|
166
|
-
title={localization.toggleVisibility}
|
|
167
|
-
>
|
|
133
|
+
<Tooltip {...getCommonTooltipProps()} title={localization.toggleVisibility}>
|
|
168
134
|
<Switch />
|
|
169
135
|
</Tooltip>
|
|
170
136
|
}
|
|
@@ -181,9 +147,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
|
181
147
|
}}
|
|
182
148
|
/>
|
|
183
149
|
) : (
|
|
184
|
-
<Typography sx={{ alignSelf: 'center' }}>
|
|
185
|
-
{columnDef.header}
|
|
186
|
-
</Typography>
|
|
150
|
+
<Typography sx={{ alignSelf: 'center' }}>{columnDef.header}</Typography>
|
|
187
151
|
)}
|
|
188
152
|
</Box>
|
|
189
153
|
</MenuItem>
|
|
@@ -11,25 +11,16 @@ interface Person {
|
|
|
11
11
|
|
|
12
12
|
const data: Person[] = [{ name: 'Alice' }];
|
|
13
13
|
|
|
14
|
-
const columns = (): MRT_ColumnDef<Person>[] => [
|
|
15
|
-
{ accessorKey: 'name', header: 'Name' },
|
|
16
|
-
];
|
|
14
|
+
const columns = (): MRT_ColumnDef<Person>[] => [{ accessorKey: 'name', header: 'Name' }];
|
|
17
15
|
|
|
18
16
|
describe('row editing', () => {
|
|
19
17
|
test('opens the edit modal when the edit button is clicked', async () => {
|
|
20
18
|
const user = userEvent.setup();
|
|
21
19
|
const { baseElement, container } = render(
|
|
22
|
-
<MaterialReactTable
|
|
23
|
-
columns={columns()}
|
|
24
|
-
data={data}
|
|
25
|
-
editDisplayMode="modal"
|
|
26
|
-
enableEditing
|
|
27
|
-
/>,
|
|
20
|
+
<MaterialReactTable columns={columns()} data={data} editDisplayMode="modal" enableEditing />,
|
|
28
21
|
);
|
|
29
22
|
|
|
30
|
-
await user.click(
|
|
31
|
-
container.querySelector('[aria-label="Edit"]') as HTMLElement,
|
|
32
|
-
);
|
|
23
|
+
await user.click(container.querySelector('[aria-label="Edit"]') as HTMLElement);
|
|
33
24
|
|
|
34
25
|
expect(baseElement.querySelectorAll('input').length).toBeGreaterThan(0);
|
|
35
26
|
});
|
|
@@ -37,17 +28,10 @@ describe('row editing', () => {
|
|
|
37
28
|
test('opens inline inputs when editDisplayMode is row', async () => {
|
|
38
29
|
const user = userEvent.setup();
|
|
39
30
|
const { container } = render(
|
|
40
|
-
<MaterialReactTable
|
|
41
|
-
columns={columns()}
|
|
42
|
-
data={data}
|
|
43
|
-
editDisplayMode="row"
|
|
44
|
-
enableEditing
|
|
45
|
-
/>,
|
|
31
|
+
<MaterialReactTable columns={columns()} data={data} editDisplayMode="row" enableEditing />,
|
|
46
32
|
);
|
|
47
33
|
|
|
48
|
-
await user.click(
|
|
49
|
-
container.querySelector('[aria-label="Edit"]') as HTMLElement,
|
|
50
|
-
);
|
|
34
|
+
await user.click(container.querySelector('[aria-label="Edit"]') as HTMLElement);
|
|
51
35
|
|
|
52
36
|
expect(container.querySelectorAll('tbody input').length).toBeGreaterThan(0);
|
|
53
37
|
});
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import { Dialog, type DialogProps } from '@mui/material';
|
|
2
|
-
import { DialogActions } from '@mui/material';
|
|
3
|
-
import { DialogContent } from '@mui/material';
|
|
4
|
-
import { DialogTitle } from '@mui/material';
|
|
5
|
-
import { Stack } from '@mui/material';
|
|
1
|
+
import { Dialog, DialogActions, DialogContent, type DialogProps, DialogTitle, Stack } from '@mui/material';
|
|
6
2
|
|
|
7
|
-
import {
|
|
8
|
-
type MRT_Row,
|
|
9
|
-
type MRT_RowData,
|
|
10
|
-
type MRT_TableInstance,
|
|
11
|
-
} from '../../types';
|
|
3
|
+
import { type MRT_Row, type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
12
4
|
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
13
5
|
import { MRT_EditActionButtons } from '../buttons/MRT_EditActionButtons';
|
|
14
6
|
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
|
|
15
7
|
|
|
16
|
-
export interface MRT_EditRowModalProps<TData extends MRT_RowData>
|
|
17
|
-
extends Partial<DialogProps> {
|
|
8
|
+
export interface MRT_EditRowModalProps<TData extends MRT_RowData> extends Partial<DialogProps> {
|
|
18
9
|
open: boolean;
|
|
19
10
|
table: MRT_TableInstance<TData>;
|
|
20
11
|
}
|
|
@@ -23,7 +14,7 @@ export const MRT_EditRowModal = <TData extends MRT_RowData>({
|
|
|
23
14
|
open,
|
|
24
15
|
table,
|
|
25
16
|
...rest
|
|
26
|
-
}: MRT_EditRowModalProps<TData>) => {
|
|
17
|
+
}: MRT_EditRowModalProps<TData>): JSX.Element => {
|
|
27
18
|
const {
|
|
28
19
|
options: {
|
|
29
20
|
localization,
|
|
@@ -42,21 +33,14 @@ export const MRT_EditRowModal = <TData extends MRT_RowData>({
|
|
|
42
33
|
|
|
43
34
|
const dialogProps = {
|
|
44
35
|
...parseFromValuesOrFunc(muiEditRowDialogProps, { row, table }),
|
|
45
|
-
...(creatingRow &&
|
|
46
|
-
parseFromValuesOrFunc(muiCreateRowModalProps, { row, table })),
|
|
36
|
+
...(creatingRow && parseFromValuesOrFunc(muiCreateRowModalProps, { row, table })),
|
|
47
37
|
...rest,
|
|
48
38
|
};
|
|
49
39
|
|
|
50
40
|
const internalEditComponents = row
|
|
51
41
|
.getAllCells()
|
|
52
42
|
.filter((cell) => cell.column.columnDef.columnDefType === 'data')
|
|
53
|
-
.map((cell) =>
|
|
54
|
-
<MRT_EditCellTextField
|
|
55
|
-
cell={cell as any}
|
|
56
|
-
key={cell.id}
|
|
57
|
-
table={table as any}
|
|
58
|
-
/>
|
|
59
|
-
));
|
|
43
|
+
.map((cell) => <MRT_EditCellTextField cell={cell} key={cell.id} table={table} />);
|
|
60
44
|
|
|
61
45
|
return (
|
|
62
46
|
<Dialog
|
|
@@ -70,7 +54,7 @@ export const MRT_EditRowModal = <TData extends MRT_RowData>({
|
|
|
70
54
|
onEditingRowCancel?.({ row, table });
|
|
71
55
|
setEditingRow(null);
|
|
72
56
|
}
|
|
73
|
-
row._valuesCache = {}
|
|
57
|
+
row._valuesCache = {}; //reset values cache
|
|
74
58
|
dialogProps.onClose?.(event, reason);
|
|
75
59
|
}}
|
|
76
60
|
open={open}
|
|
@@ -88,9 +72,7 @@ export const MRT_EditRowModal = <TData extends MRT_RowData>({
|
|
|
88
72
|
table,
|
|
89
73
|
})) ?? (
|
|
90
74
|
<>
|
|
91
|
-
<DialogTitle sx={{ textAlign: 'center' }}>
|
|
92
|
-
{localization.edit}
|
|
93
|
-
</DialogTitle>
|
|
75
|
+
<DialogTitle sx={{ textAlign: 'center' }}>{localization.edit}</DialogTitle>
|
|
94
76
|
<DialogContent>
|
|
95
77
|
<form onSubmit={(e) => e.preventDefault()}>
|
|
96
78
|
<Stack
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Table, type TableProps } from '@mui/material';
|
|
2
|
-
import {
|
|
2
|
+
import { type CSSObject } from '@mui/material/styles';
|
|
3
3
|
|
|
4
4
|
import { useMRT_ColumnVirtualizer } from '../../hooks/useMRT_ColumnVirtualizer';
|
|
5
5
|
import { type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
@@ -13,14 +13,10 @@ export interface MRT_TableProps<TData extends MRT_RowData> extends TableProps {
|
|
|
13
13
|
table: MRT_TableInstance<TData>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const MRT_Table = <TData extends MRT_RowData>({
|
|
17
|
-
table,
|
|
18
|
-
...rest
|
|
19
|
-
}: MRT_TableProps<TData>) => {
|
|
16
|
+
export const MRT_Table = <TData extends MRT_RowData>({ table, ...rest }: MRT_TableProps<TData>): JSX.Element => {
|
|
20
17
|
const {
|
|
21
18
|
getFlatHeaders,
|
|
22
19
|
options: {
|
|
23
|
-
columns,
|
|
24
20
|
enableStickyHeader,
|
|
25
21
|
enableTableFooter,
|
|
26
22
|
enableTableHead,
|
|
@@ -30,8 +26,7 @@ export const MRT_Table = <TData extends MRT_RowData>({
|
|
|
30
26
|
renderCaption,
|
|
31
27
|
},
|
|
32
28
|
} = table;
|
|
33
|
-
const { columnResizing,
|
|
34
|
-
table.state;
|
|
29
|
+
const { columnResizing, isFullScreen } = table.state;
|
|
35
30
|
|
|
36
31
|
const tableProps = {
|
|
37
32
|
...parseFromValuesOrFunc(muiTableProps, { table }),
|
|
@@ -40,17 +35,14 @@ export const MRT_Table = <TData extends MRT_RowData>({
|
|
|
40
35
|
|
|
41
36
|
const Caption = parseFromValuesOrFunc(renderCaption, { table });
|
|
42
37
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return colSizes;
|
|
53
|
-
}, [columns, columnSizing, columnResizing, columnVisibility]);
|
|
38
|
+
const headers = getFlatHeaders();
|
|
39
|
+
const columnSizeVars: { [key: string]: number } = {};
|
|
40
|
+
for (let i = 0; i < headers.length; i++) {
|
|
41
|
+
const header = headers[i];
|
|
42
|
+
const colSize = header.getSize();
|
|
43
|
+
columnSizeVars[`--header-${parseCSSVarId(header.id)}-size`] = colSize;
|
|
44
|
+
columnSizeVars[`--col-${parseCSSVarId(header.column.id)}-size`] = colSize;
|
|
45
|
+
}
|
|
54
46
|
|
|
55
47
|
const columnVirtualizer = useMRT_ColumnVirtualizer(table);
|
|
56
48
|
|
|
@@ -68,7 +60,7 @@ export const MRT_Table = <TData extends MRT_RowData>({
|
|
|
68
60
|
borderCollapse: 'separate',
|
|
69
61
|
display: layoutMode?.startsWith('grid') ? 'grid' : undefined,
|
|
70
62
|
position: 'relative',
|
|
71
|
-
...(parseFromValuesOrFunc(tableProps?.sx, theme) as
|
|
63
|
+
...(parseFromValuesOrFunc(tableProps?.sx, theme) as CSSObject),
|
|
72
64
|
})}
|
|
73
65
|
>
|
|
74
66
|
{!!Caption && <caption>{Caption}</caption>}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { act, render } from '@testing-library/react';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { type MRT_ColumnDef } from '../../types';
|
|
5
|
+
import { MaterialReactTable } from '../MaterialReactTable';
|
|
6
|
+
|
|
7
|
+
interface Person {
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const data: Person[] = [{ name: 'Alice' }];
|
|
12
|
+
|
|
13
|
+
const columns: MRT_ColumnDef<Person>[] = [{ accessorKey: 'name', header: 'Name' }];
|
|
14
|
+
|
|
15
|
+
const toolbarHeight = 50;
|
|
16
|
+
|
|
17
|
+
const toolbarHeights: Record<string, number> = {};
|
|
18
|
+
|
|
19
|
+
const resizeObservers: FakeResizeObserver[] = [];
|
|
20
|
+
|
|
21
|
+
class FakeResizeObserver {
|
|
22
|
+
callback: ResizeObserverCallback;
|
|
23
|
+
|
|
24
|
+
targets = new Set<Element>();
|
|
25
|
+
|
|
26
|
+
constructor(callback: ResizeObserverCallback) {
|
|
27
|
+
this.callback = callback;
|
|
28
|
+
resizeObservers.push(this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
disconnect() {
|
|
32
|
+
this.targets.clear();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
observe(target: Element) {
|
|
36
|
+
this.targets.add(target);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
unobserve(target: Element) {
|
|
40
|
+
this.targets.delete(target);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const notifyResizeObservers = () => {
|
|
45
|
+
for (const resizeObserver of [...resizeObservers]) {
|
|
46
|
+
resizeObserver.callback([], {} as ResizeObserver);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const notifyResizeObserversOf = (target: Element) => {
|
|
51
|
+
for (const resizeObserver of [...resizeObservers]) {
|
|
52
|
+
if (resizeObserver.targets.has(target)) {
|
|
53
|
+
resizeObserver.callback([], {} as ResizeObserver);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
describe('table container max height', () => {
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
vi.stubGlobal('ResizeObserver', FakeResizeObserver);
|
|
61
|
+
vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockImplementation(function (this: HTMLElement) {
|
|
62
|
+
return this.dataset.toolbar ? (toolbarHeights[this.dataset.toolbar] ?? toolbarHeight) : 0;
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
afterEach(() => {
|
|
67
|
+
resizeObservers.length = 0;
|
|
68
|
+
for (const toolbar of Object.keys(toolbarHeights)) {
|
|
69
|
+
delete toolbarHeights[toolbar];
|
|
70
|
+
}
|
|
71
|
+
vi.unstubAllGlobals();
|
|
72
|
+
vi.restoreAllMocks();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('subtracts the top and bottom toolbar heights', () => {
|
|
76
|
+
const { container } = render(
|
|
77
|
+
<MaterialReactTable
|
|
78
|
+
columns={columns}
|
|
79
|
+
data={data}
|
|
80
|
+
enableStickyHeader
|
|
81
|
+
muiBottomToolbarProps={{ 'data-toolbar': 'bottom' } as object}
|
|
82
|
+
muiTableContainerProps={{ 'data-testid': 'table-container' } as object}
|
|
83
|
+
muiTopToolbarProps={{ 'data-toolbar': 'top' } as object}
|
|
84
|
+
/>,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
act(() => {
|
|
88
|
+
notifyResizeObservers();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const tableContainer = container.querySelector('[data-testid="table-container"]') as HTMLElement;
|
|
92
|
+
|
|
93
|
+
expect(getComputedStyle(tableContainer).maxHeight).toBe(`${window.innerHeight - toolbarHeight * 2}px`);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('includes a bottom toolbar that is turned on after mount', () => {
|
|
97
|
+
const table = (enableBottomToolbar: boolean) => (
|
|
98
|
+
<MaterialReactTable
|
|
99
|
+
columns={columns}
|
|
100
|
+
data={data}
|
|
101
|
+
enableBottomToolbar={enableBottomToolbar}
|
|
102
|
+
enableStickyHeader
|
|
103
|
+
muiBottomToolbarProps={{ 'data-toolbar': 'bottom' } as object}
|
|
104
|
+
muiTableContainerProps={{ 'data-testid': 'table-container' } as object}
|
|
105
|
+
muiTopToolbarProps={{ 'data-toolbar': 'top' } as object}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
const { container, rerender } = render(table(false));
|
|
109
|
+
|
|
110
|
+
rerender(table(true));
|
|
111
|
+
act(() => {
|
|
112
|
+
notifyResizeObservers();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const tableContainer = container.querySelector('[data-testid="table-container"]') as HTMLElement;
|
|
116
|
+
|
|
117
|
+
expect(getComputedStyle(tableContainer).maxHeight).toBe(`${window.innerHeight - toolbarHeight * 2}px`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('re-measures a toolbar when its height changes', () => {
|
|
121
|
+
const { container } = render(
|
|
122
|
+
<MaterialReactTable
|
|
123
|
+
columns={columns}
|
|
124
|
+
data={data}
|
|
125
|
+
enableStickyHeader
|
|
126
|
+
muiBottomToolbarProps={{ 'data-toolbar': 'bottom' } as object}
|
|
127
|
+
muiTableContainerProps={{ 'data-testid': 'table-container' } as object}
|
|
128
|
+
muiTopToolbarProps={{ 'data-toolbar': 'top' } as object}
|
|
129
|
+
/>,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
act(() => {
|
|
133
|
+
notifyResizeObservers();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const topToolbar = container.querySelector('[data-toolbar="top"]') as HTMLElement;
|
|
137
|
+
toolbarHeights.top = 80;
|
|
138
|
+
|
|
139
|
+
act(() => {
|
|
140
|
+
notifyResizeObserversOf(topToolbar);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const tableContainer = container.querySelector('[data-testid="table-container"]') as HTMLElement;
|
|
144
|
+
|
|
145
|
+
expect(getComputedStyle(tableContainer).maxHeight).toBe(`${window.innerHeight - 80 - toolbarHeight}px`);
|
|
146
|
+
});
|
|
147
|
+
});
|