material-react-table-narender 2.13.20 → 2.13.22

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.13.20",
2
+ "version": "2.13.22",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table-narender",
5
5
  "description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
@@ -0,0 +1,49 @@
1
+ import { useState } from 'react';
2
+ import IconButton, { type IconButtonProps } from '@mui/material/IconButton';
3
+ import Tooltip from '@mui/material/Tooltip';
4
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
5
+
6
+ export interface MRT_ToggleNavigationButtonProps<TData extends MRT_RowData>
7
+ extends IconButtonProps {
8
+ table: MRT_TableInstance<TData>;
9
+ }
10
+
11
+ export const MRT_ToggleNavigationButton = <TData extends MRT_RowData>({
12
+ table,
13
+ ...rest
14
+ }: MRT_ToggleNavigationButtonProps<TData>) => {
15
+ const {
16
+ getState,
17
+ options: {
18
+ icons: { FullscreenExitIcon, FullscreenIcon },
19
+ localization,
20
+ },
21
+ setEnableKeyboardShortcuts,
22
+ } = table;
23
+ const { enableKeyboardShortcuts } = getState();
24
+
25
+ const [tooltipOpened, setTooltipOpened] = useState(false);
26
+
27
+ const handleToggleFullScreen = () => {
28
+ setTooltipOpened(false);
29
+ setEnableKeyboardShortcuts(!enableKeyboardShortcuts);
30
+ };
31
+
32
+ return (
33
+ <Tooltip
34
+ open={tooltipOpened}
35
+ title={rest?.title ?? localization.toggleFullScreen}
36
+ >
37
+ <IconButton
38
+ aria-label={localization.toggleFullScreen}
39
+ onClick={handleToggleFullScreen}
40
+ onMouseEnter={() => setTooltipOpened(true)}
41
+ onMouseLeave={() => setTooltipOpened(false)}
42
+ {...rest}
43
+ title={undefined}
44
+ >
45
+ {enableKeyboardShortcuts ? <FullscreenExitIcon /> : <FullscreenIcon />}
46
+ </IconButton>
47
+ </Tooltip>
48
+ );
49
+ };
@@ -40,7 +40,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
40
40
  enableColumnPinning,
41
41
  enableHiding,
42
42
  localization,
43
- enableColumnResizing,
43
+ // enableColumnResizing,
44
44
  mrtTheme: { menuBackgroundColor },
45
45
  },
46
46
  } = table;
@@ -141,7 +141,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
141
141
  {localization.showAll}
142
142
  </Button>
143
143
  )}
144
- {
144
+ {/* {
145
145
  enableColumnResizing && (
146
146
  <Button
147
147
  onClick={() => {
@@ -151,7 +151,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
151
151
  {localization.resetColumnSize}
152
152
  </Button>
153
153
  )
154
- }
154
+ } */}
155
155
  </Box>
156
156
  <Divider />
157
157
  {allColumns.map((column, index) => (
@@ -6,6 +6,7 @@ import { MRT_ToggleDensePaddingButton } from '../buttons/MRT_ToggleDensePaddingB
6
6
  import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
7
7
  import { MRT_ToggleFullScreenButton } from '../buttons/MRT_ToggleFullScreenButton';
8
8
  import { MRT_ToggleGlobalFilterButton } from '../buttons/MRT_ToggleGlobalFilterButton';
9
+ import { MRT_ToggleNavigationButton } from '../buttons/MRT_ToggleNavigationButton';
9
10
 
10
11
  export interface MRT_ToolbarInternalButtonsProps<TData extends MRT_RowData>
11
12
  extends BoxProps {
@@ -29,6 +30,7 @@ export const MRT_ToolbarInternalButtons = <TData extends MRT_RowData>({
29
30
  enableHiding,
30
31
  initialState,
31
32
  renderToolbarInternalActions,
33
+ enableKeyboardShortcuts
32
34
  },
33
35
  } = table;
34
36
 
@@ -65,6 +67,10 @@ export const MRT_ToolbarInternalButtons = <TData extends MRT_RowData>({
65
67
  {enableFullScreenToggle && (
66
68
  <MRT_ToggleFullScreenButton table={table} />
67
69
  )}
70
+ {/* {enableKeyboardShortcuts && (
71
+ <MRT_ToggleNavigationButton table={table} />
72
+ )} */}
73
+ <MRT_ToggleNavigationButton table={table} />
68
74
  </>
69
75
  )}
70
76
  </Box>
package/src/types.ts CHANGED
@@ -247,6 +247,7 @@ export interface MRT_Localization {
247
247
  thenBy: string;
248
248
  toggleDensity: string;
249
249
  toggleFullScreen: string;
250
+ // keyboardNavigation: string;
250
251
  toggleSelectAll: string;
251
252
  toggleSelectRow: string;
252
253
  toggleVisibility: string;
@@ -91,39 +91,49 @@ export const cellKeyboardShortcuts = <TData extends MRT_RowData = MRT_RowData>({
91
91
  const { enableKeyboardShortcuts } = getState();
92
92
 
93
93
  // alt + n
94
- if (event.altKey && event.key.toLocaleLowerCase() === 'n') {
95
- event.preventDefault();
96
- setEnableKeyboardShortcuts(!enableKeyboardShortcuts);
97
- const currentCell = event.currentTarget;
98
-
99
-
100
- if (enableKeyboardShortcuts) {
101
- const input = currentCell.querySelector('input') as HTMLInputElement;
102
- const select = currentCell.querySelector('select') as HTMLSelectElement;
103
- const checkbox = currentCell.querySelector('input[type="checkbox"]') as HTMLInputElement;
104
- const button = currentCell.querySelector('button') as HTMLButtonElement;
105
- const autocomplete = currentCell.querySelector('.MuiAutocomplete-root input[type="text"]') as HTMLInputElement;
106
-
107
-
108
- if (autocomplete) {
109
- autocomplete.focus();
110
- autocomplete.select?.();
111
- } else if (input) {
112
- input.focus();
113
- input.select?.();
114
- } else if (select) {
115
- select.focus();
116
- } else if (checkbox) {
117
- checkbox.focus();
118
- // checkbox.click();
119
- } else if (button) {
120
- button.focus();
121
- } else {
122
- currentCell.focus();
123
- }
124
- }
94
+ // if (event.altKey && event.key.toLocaleLowerCase() === 'n') {
95
+ // event.preventDefault();
96
+ // setEnableKeyboardShortcuts(!enableKeyboardShortcuts);
97
+ // const currentCell = event.currentTarget;
98
+
99
+
100
+ // if (enableKeyboardShortcuts) {
101
+ // const input = currentCell.querySelector('input') as HTMLInputElement;
102
+ // const select = currentCell.querySelector('select') as HTMLSelectElement;
103
+ // const checkbox = currentCell.querySelector('input[type="checkbox"]') as HTMLInputElement;
104
+ // const button = currentCell.querySelector('button') as HTMLButtonElement;
105
+ // const autocomplete = currentCell.querySelector('.MuiAutocomplete-root input[type="text"]') as HTMLInputElement;
106
+
107
+
108
+ // if (autocomplete) {
109
+ // autocomplete.focus();
110
+ // autocomplete.select?.();
111
+ // } else if (input) {
112
+ // input.focus();
113
+ // input.select?.();
114
+ // } else if (select) {
115
+ // select.focus();
116
+ // } else if (checkbox) {
117
+ // checkbox.focus();
118
+ // // checkbox.click();
119
+ // } else if (button) {
120
+ // button.focus();
121
+ // } else {
122
+ // currentCell.focus();
123
+ // }
124
+ // }
125
+
126
+ // }
127
+
128
+
129
+ // if (event.altKey && event.key.toLocaleLowerCase() === 'n') {
130
+ // event.preventDefault();
131
+ // setEnableKeyboardShortcuts(!enableKeyboardShortcuts);
132
+ // }
133
+
134
+
135
+
125
136
 
126
- }
127
137
 
128
138
  // if (!table.options.enableKeyboardShortcuts) return;
129
139
  if (!enableKeyboardShortcuts) return
@@ -195,11 +205,11 @@ const autocomplete = currentCell.querySelector('.MuiAutocomplete-root input[type
195
205
  // Focus the appropriate element
196
206
  if (autocomplete) {
197
207
  autocomplete.focus();
198
- autocomplete.select?.();
208
+ // autocomplete.select?.();
199
209
  }
200
210
  else if (input) {
201
211
  input.focus();
202
- input.select?.();
212
+ // input.select?.();
203
213
  } else if (select) {
204
214
  select.focus();
205
215
  } else if (checkbox) {
@@ -241,8 +251,6 @@ else if (input) {
241
251
 
242
252
  if (['ArrowDown','ArrowUp'].includes(event.key)) {
243
253
  const autocomplete = currentCell.querySelector('.MuiAutocomplete-root input[type="text"]');
244
-
245
- // Check if the autocomplete input exists and is focused
246
254
  if (autocomplete && document.activeElement === autocomplete) {
247
255
 
248
256
 
@@ -259,14 +267,11 @@ if (['ArrowDown','ArrowUp'].includes(event.key)) {
259
267
  }
260
268
  }
261
269
  }
262
-
263
- // Additional logic if not an Autocomplete or not focused
264
270
  }
265
271
 
266
272
 
267
273
 
268
274
 
269
-
270
275
  const currentRow = parentElement || currentCell.closest('tr');
271
276
  const tableElement = containerElement || currentCell.closest('table');
272
277
  const allCells =
@@ -277,6 +282,8 @@ if (['ArrowDown','ArrowUp'].includes(event.key)) {
277
282
  const currentIndex = parseInt(
278
283
  currentCell.getAttribute('data-index') || '0',
279
284
  );
285
+
286
+
280
287
  let nextCell: HTMLElement | undefined = undefined;
281
288
 
282
289
  //home/end first or last cell in row
@@ -317,6 +324,12 @@ if (['ArrowDown','ArrowUp'].includes(event.key)) {
317
324
  ) as HTMLElement | undefined;
318
325
  };
319
326
 
327
+ // const findCurrentCell = () => {
328
+ // return allCells.find((cell) =>
329
+ // cell.matches(`[data-index="${currentIndex}"]`),
330
+ // );
331
+ // }
332
+
320
333
  switch (event.key) {
321
334
  case 'ArrowRight':
322
335
  nextCell = findAdjacentCell(currentIndex + 1, 'f');