material-react-table-narender 2.13.19 → 2.13.21

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.13.19",
2
+ "version": "2.13.21",
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.keyboardNavigation}
36
+ >
37
+ <IconButton
38
+ aria-label={localization.keyboardNavigation}
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,9 @@ 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
+ )}
68
73
  </>
69
74
  )}
70
75
  </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;
@@ -90,39 +90,50 @@ export const cellKeyboardShortcuts = <TData extends MRT_RowData = MRT_RowData>({
90
90
 
91
91
  const { enableKeyboardShortcuts } = getState();
92
92
 
93
- if (event.altKey) {
94
- event.preventDefault();
95
- setEnableKeyboardShortcuts(!enableKeyboardShortcuts);
96
- const currentCell = event.currentTarget;
97
-
98
-
99
- if (enableKeyboardShortcuts) {
100
- const input = currentCell.querySelector('input') as HTMLInputElement;
101
- const select = currentCell.querySelector('select') as HTMLSelectElement;
102
- const checkbox = currentCell.querySelector('input[type="checkbox"]') as HTMLInputElement;
103
- const button = currentCell.querySelector('button') as HTMLButtonElement;
104
- const autocomplete = currentCell.querySelector('.MuiAutocomplete-root input[type="text"]') as HTMLInputElement;
105
-
106
-
107
- if (autocomplete) {
108
- autocomplete.focus();
109
- autocomplete.select?.();
110
- } else if (input) {
111
- input.focus();
112
- input.select?.();
113
- } else if (select) {
114
- select.focus();
115
- } else if (checkbox) {
116
- checkbox.focus();
117
- // checkbox.click();
118
- } else if (button) {
119
- button.focus();
120
- } else {
121
- currentCell.focus();
122
- }
123
- }
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
+ // }
125
+
126
+ // }
127
+
128
+
129
+ // if (event.altKey && event.key.toLocaleLowerCase() === 'n') {
130
+ // event.preventDefault();
131
+ // setEnableKeyboardShortcuts(!enableKeyboardShortcuts);
132
+ // }
133
+
134
+
135
+
124
136
 
125
- }
126
137
 
127
138
  // if (!table.options.enableKeyboardShortcuts) return;
128
139
  if (!enableKeyboardShortcuts) return
@@ -194,11 +205,11 @@ const autocomplete = currentCell.querySelector('.MuiAutocomplete-root input[type
194
205
  // Focus the appropriate element
195
206
  if (autocomplete) {
196
207
  autocomplete.focus();
197
- autocomplete.select?.();
208
+ // autocomplete.select?.();
198
209
  }
199
210
  else if (input) {
200
211
  input.focus();
201
- input.select?.();
212
+ // input.select?.();
202
213
  } else if (select) {
203
214
  select.focus();
204
215
  } else if (checkbox) {
@@ -240,8 +251,6 @@ else if (input) {
240
251
 
241
252
  if (['ArrowDown','ArrowUp'].includes(event.key)) {
242
253
  const autocomplete = currentCell.querySelector('.MuiAutocomplete-root input[type="text"]');
243
-
244
- // Check if the autocomplete input exists and is focused
245
254
  if (autocomplete && document.activeElement === autocomplete) {
246
255
 
247
256
 
@@ -258,14 +267,11 @@ if (['ArrowDown','ArrowUp'].includes(event.key)) {
258
267
  }
259
268
  }
260
269
  }
261
-
262
- // Additional logic if not an Autocomplete or not focused
263
270
  }
264
271
 
265
272
 
266
273
 
267
274
 
268
-
269
275
  const currentRow = parentElement || currentCell.closest('tr');
270
276
  const tableElement = containerElement || currentCell.closest('table');
271
277
  const allCells =
@@ -276,6 +282,8 @@ if (['ArrowDown','ArrowUp'].includes(event.key)) {
276
282
  const currentIndex = parseInt(
277
283
  currentCell.getAttribute('data-index') || '0',
278
284
  );
285
+
286
+
279
287
  let nextCell: HTMLElement | undefined = undefined;
280
288
 
281
289
  //home/end first or last cell in row
@@ -316,6 +324,12 @@ if (['ArrowDown','ArrowUp'].includes(event.key)) {
316
324
  ) as HTMLElement | undefined;
317
325
  };
318
326
 
327
+ // const findCurrentCell = () => {
328
+ // return allCells.find((cell) =>
329
+ // cell.matches(`[data-index="${currentIndex}"]`),
330
+ // );
331
+ // }
332
+
319
333
  switch (event.key) {
320
334
  case 'ArrowRight':
321
335
  nextCell = findAdjacentCell(currentIndex + 1, 'f');