material-react-table 2.0.0-beta.14 → 2.0.0-beta.15
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +19 -4
- package/dist/index.esm.js +27 -34
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +27 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/column.utils.ts +17 -0
- package/src/inputs/MRT_EditCellTextField.tsx +18 -28
- package/src/inputs/MRT_FilterTextField.tsx +39 -51
- package/src/types.ts +22 -3
package/package.json
CHANGED
package/src/column.utils.ts
CHANGED
@@ -348,3 +348,20 @@ export function createMRTColumnHelper<
|
|
348
348
|
group: (column) => column as MRT_GroupColumnDef<TData>,
|
349
349
|
};
|
350
350
|
}
|
351
|
+
|
352
|
+
export const getValueAndLabel = (
|
353
|
+
option: { label?: string; text?: string; value: string } | string,
|
354
|
+
): { label: string; value: string } => {
|
355
|
+
let label: string = '';
|
356
|
+
let value: string = '';
|
357
|
+
if (option) {
|
358
|
+
if (typeof option !== 'object') {
|
359
|
+
label = option;
|
360
|
+
value = option;
|
361
|
+
} else {
|
362
|
+
label = option.label ?? option.text ?? option.value;
|
363
|
+
value = option.value ?? label;
|
364
|
+
}
|
365
|
+
}
|
366
|
+
return { label, value };
|
367
|
+
};
|
@@ -7,7 +7,7 @@ import {
|
|
7
7
|
import MenuItem from '@mui/material/MenuItem';
|
8
8
|
import TextField from '@mui/material/TextField';
|
9
9
|
import { type TextFieldProps } from '@mui/material/TextField';
|
10
|
-
import { parseFromValuesOrFunc } from '../column.utils';
|
10
|
+
import { getValueAndLabel, parseFromValuesOrFunc } from '../column.utils';
|
11
11
|
import {
|
12
12
|
type MRT_Cell,
|
13
13
|
type MRT_RowData,
|
@@ -150,33 +150,23 @@ export const MRT_EditCellTextField = <TData extends MRT_RowData>({
|
|
150
150
|
onKeyDown={handleEnterKeyDown}
|
151
151
|
>
|
152
152
|
{textFieldProps.children ??
|
153
|
-
columnDef?.editSelectOptions?.map(
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
gap: '0.5rem',
|
171
|
-
m: 0,
|
172
|
-
}}
|
173
|
-
value={value}
|
174
|
-
>
|
175
|
-
{text}
|
176
|
-
</MenuItem>
|
177
|
-
);
|
178
|
-
},
|
179
|
-
)}
|
153
|
+
columnDef?.editSelectOptions?.map((option) => {
|
154
|
+
const { label, value } = getValueAndLabel(option);
|
155
|
+
return (
|
156
|
+
<MenuItem
|
157
|
+
key={value}
|
158
|
+
sx={{
|
159
|
+
alignItems: 'center',
|
160
|
+
display: 'flex',
|
161
|
+
gap: '0.5rem',
|
162
|
+
m: 0,
|
163
|
+
}}
|
164
|
+
value={value}
|
165
|
+
>
|
166
|
+
{label}
|
167
|
+
</MenuItem>
|
168
|
+
);
|
169
|
+
})}
|
180
170
|
</TextField>
|
181
171
|
);
|
182
172
|
};
|
@@ -21,7 +21,7 @@ import {
|
|
21
21
|
DatePicker,
|
22
22
|
type DatePickerProps,
|
23
23
|
} from '@mui/x-date-pickers/DatePicker';
|
24
|
-
import { parseFromValuesOrFunc } from '../column.utils';
|
24
|
+
import { getValueAndLabel, parseFromValuesOrFunc } from '../column.utils';
|
25
25
|
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
26
26
|
import {
|
27
27
|
type MRT_Header,
|
@@ -309,6 +309,7 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
309
309
|
</label>
|
310
310
|
) : null,
|
311
311
|
inputProps: {
|
312
|
+
'aria-label': filterPlaceholder,
|
312
313
|
autoComplete: 'new-password', // disable autocomplete and autofill
|
313
314
|
disabled: !!filterChipLabel,
|
314
315
|
sx: {
|
@@ -373,9 +374,13 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
373
374
|
) : isAutocompleteFilter ? (
|
374
375
|
<Autocomplete
|
375
376
|
freeSolo
|
376
|
-
getOptionLabel={(option) => option}
|
377
|
-
onChange={(_e, newValue) =>
|
378
|
-
|
377
|
+
getOptionLabel={(option) => getValueAndLabel(option).label}
|
378
|
+
onChange={(_e, newValue) =>
|
379
|
+
handleChange(getValueAndLabel(newValue).value)
|
380
|
+
}
|
381
|
+
options={
|
382
|
+
dropdownOptions?.map((option) => getValueAndLabel(option)) ?? []
|
383
|
+
}
|
379
384
|
{...autocompleteProps}
|
380
385
|
renderInput={(builtinTextFieldProps) => (
|
381
386
|
<TextField
|
@@ -407,19 +412,13 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
407
412
|
) : (
|
408
413
|
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: '2px' }}>
|
409
414
|
{(selected as string[])?.map((value) => {
|
410
|
-
const selectedValue = dropdownOptions?.find(
|
411
|
-
option
|
412
|
-
? option.value === value
|
413
|
-
: option === value,
|
415
|
+
const selectedValue = dropdownOptions?.find(
|
416
|
+
(option) => getValueAndLabel(option).value === value,
|
414
417
|
);
|
415
418
|
return (
|
416
419
|
<Chip
|
417
420
|
key={value}
|
418
|
-
label={
|
419
|
-
selectedValue instanceof Object
|
420
|
-
? selectedValue.text
|
421
|
-
: selectedValue
|
422
|
-
}
|
421
|
+
label={getValueAndLabel(selectedValue).label}
|
423
422
|
/>
|
424
423
|
);
|
425
424
|
})}
|
@@ -438,44 +437,33 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
438
437
|
</MenuItem>,
|
439
438
|
...[
|
440
439
|
textFieldProps.children ??
|
441
|
-
dropdownOptions?.map(
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
{
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
).includes(value)}
|
469
|
-
sx={{ mr: '0.5rem' }}
|
470
|
-
/>
|
471
|
-
)}
|
472
|
-
{text}{' '}
|
473
|
-
{!columnDef.filterSelectOptions &&
|
474
|
-
`(${facetedUniqueValues.get(value)})`}
|
475
|
-
</MenuItem>
|
476
|
-
);
|
477
|
-
},
|
478
|
-
),
|
440
|
+
dropdownOptions?.map((option, index) => {
|
441
|
+
const { label, value } = getValueAndLabel(option);
|
442
|
+
return (
|
443
|
+
<MenuItem
|
444
|
+
key={`${index}-${value}`}
|
445
|
+
sx={{
|
446
|
+
alignItems: 'center',
|
447
|
+
display: 'flex',
|
448
|
+
gap: '0.5rem',
|
449
|
+
m: 0,
|
450
|
+
}}
|
451
|
+
value={value}
|
452
|
+
>
|
453
|
+
{isMultiSelectFilter && (
|
454
|
+
<Checkbox
|
455
|
+
checked={(
|
456
|
+
(column.getFilterValue() ?? []) as string[]
|
457
|
+
).includes(value)}
|
458
|
+
sx={{ mr: '0.5rem' }}
|
459
|
+
/>
|
460
|
+
)}
|
461
|
+
{label}{' '}
|
462
|
+
{!columnDef.filterSelectOptions &&
|
463
|
+
`(${facetedUniqueValues.get(value)})`}
|
464
|
+
</MenuItem>
|
465
|
+
);
|
466
|
+
}),
|
479
467
|
],
|
480
468
|
]}
|
481
469
|
</TextField>
|
package/src/types.ts
CHANGED
@@ -424,7 +424,17 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
|
|
424
424
|
LiteralUnion<string & MRT_FilterOption>
|
425
425
|
> | null;
|
426
426
|
columns?: MRT_ColumnDef<TData, TValue>[];
|
427
|
-
editSelectOptions?: (
|
427
|
+
editSelectOptions?: (
|
428
|
+
| {
|
429
|
+
label?: string;
|
430
|
+
/**
|
431
|
+
* @deprecated use `label` instead
|
432
|
+
*/
|
433
|
+
text?: string;
|
434
|
+
value: any;
|
435
|
+
}
|
436
|
+
| string
|
437
|
+
)[];
|
428
438
|
editVariant?: 'select' | 'text';
|
429
439
|
enableClickToCopy?: boolean;
|
430
440
|
enableColumnActions?: boolean;
|
@@ -434,7 +444,17 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
|
|
434
444
|
enableEditing?: ((row: MRT_Row<TData>) => boolean) | boolean;
|
435
445
|
enableFilterMatchHighlighting?: boolean;
|
436
446
|
filterFn?: MRT_FilterFn<TData>;
|
437
|
-
filterSelectOptions?: (
|
447
|
+
filterSelectOptions?: (
|
448
|
+
| {
|
449
|
+
label?: string;
|
450
|
+
/**
|
451
|
+
* @deprecated use `label` instead
|
452
|
+
*/
|
453
|
+
text?: string;
|
454
|
+
value: any;
|
455
|
+
}
|
456
|
+
| string
|
457
|
+
)[];
|
438
458
|
filterVariant?:
|
439
459
|
| 'autocomplete'
|
440
460
|
| 'checkbox'
|
@@ -1113,7 +1133,6 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
|
|
1113
1133
|
}) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>)
|
1114
1134
|
| Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>;
|
1115
1135
|
selectAllMode?: 'all' | 'page';
|
1116
|
-
selectDisplayMode?: 'checkbox' | 'radio' | 'switch';
|
1117
1136
|
/**
|
1118
1137
|
* Manage state externally any way you want, then pass it back into MRT.
|
1119
1138
|
*/
|