Skip to content

Commit 97104b0

Browse files
authored
fix: overlapping input label when filter select is outline
As stated in the API Documentation of MUI https://mui.com/material-ui/api/select/#props the label should be shrunk when display empty is true. I do not know why we need the display empty. If we remove it, the error also is removed. So you should consider what the use-case for displayEmpty really is. Fixes: #1142
1 parent 475f98d commit 97104b0

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

packages/material-react-table/src/components/inputs/MRT_FilterTextField.tsx

+32-25
Original file line numberDiff line numberDiff line change
@@ -453,31 +453,38 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
453453
<TextField
454454
select={isSelectFilter || isMultiSelectFilter}
455455
{...commonTextFieldProps}
456-
SelectProps={{
457-
MenuProps: { disableScrollLock: true },
458-
displayEmpty: true,
459-
multiple: isMultiSelectFilter,
460-
renderValue: isMultiSelectFilter
461-
? (selected: any) =>
462-
!Array.isArray(selected) || selected.length === 0 ? (
463-
<Box sx={{ opacity: 0.5 }}>{filterPlaceholder}</Box>
464-
) : (
465-
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: '2px' }}>
466-
{selected.map((value: string) => {
467-
const selectedValue = dropdownOptions?.find(
468-
(option) => getValueAndLabel(option).value === value,
469-
);
470-
return (
471-
<Chip
472-
key={value}
473-
label={getValueAndLabel(selectedValue).label}
474-
/>
475-
);
476-
})}
477-
</Box>
478-
)
479-
: undefined,
480-
...commonTextFieldProps.SelectProps,
456+
slotProps={{
457+
select: {
458+
MenuProps: { disableScrollLock: true },
459+
displayEmpty: true,
460+
multiple: isMultiSelectFilter,
461+
renderValue: isMultiSelectFilter
462+
? (selected: any) =>
463+
!Array.isArray(selected) || selected.length === 0 ? (
464+
<Box sx={{ opacity: 0.5 }}>{filterPlaceholder}</Box>
465+
) : (
466+
<Box
467+
sx={{ display: 'flex', flexWrap: 'wrap', gap: '2px' }}
468+
>
469+
{selected.map((value: string) => {
470+
const selectedValue = dropdownOptions?.find(
471+
(option) =>
472+
getValueAndLabel(option).value === value,
473+
);
474+
return (
475+
<Chip
476+
key={value}
477+
label={getValueAndLabel(selectedValue).label}
478+
/>
479+
);
480+
})}
481+
</Box>
482+
)
483+
: undefined,
484+
},
485+
inputLabel: {
486+
shrink: isSelectFilter || isMultiSelectFilter,
487+
},
481488
}}
482489
onChange={handleTextFieldChange}
483490
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}

0 commit comments

Comments
 (0)