Skip to content

Commit 72e6f6d

Browse files
committed
Fix ColumnsButton produce invalid HTML when adding the filter input
1 parent bb7ab82 commit 72e6f6d

File tree

3 files changed

+37
-35
lines changed

3 files changed

+37
-35
lines changed

packages/ra-ui-materialui/src/list/datatable/ColumnsButton.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('ColumnsButton', () => {
2929
screen
3030
.getByRole('menu')
3131
.querySelectorAll('li:not(.columns-selector-actions)')
32-
).toHaveLength(7);
32+
).toHaveLength(8); // 7 columns + the filter input li
3333
// Typing a filter
3434
fireEvent.change(
3535
screen.getByPlaceholderText('ra.action.search_columns'),
@@ -43,7 +43,7 @@ describe('ColumnsButton', () => {
4343
screen
4444
.getByRole('menu')
4545
.querySelectorAll('li:not(.columns-selector-actions)')
46-
).toHaveLength(1);
46+
).toHaveLength(2); // only the column with 'DiA' in its label should remain + the filter input li
4747
});
4848
screen.getByLabelText('Téstïng diàcritics');
4949
// Clear the filter
@@ -53,7 +53,7 @@ describe('ColumnsButton', () => {
5353
screen
5454
.getByRole('menu')
5555
.querySelectorAll('li:not(.columns-selector-actions)')
56-
).toHaveLength(7);
56+
).toHaveLength(8);
5757
});
5858
});
5959
});

packages/ra-ui-materialui/src/list/datatable/ColumnsButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
Tooltip,
99
IconButton,
1010
Popover,
11-
MenuList,
1211
PopoverOrigin,
12+
Box,
1313
} from '@mui/material';
1414
import { useRtl } from '@mui/system/RtlProvider';
1515
import ViewWeekIcon from '@mui/icons-material/ViewWeek';
@@ -103,9 +103,9 @@ export const ColumnsButton = (inProps: ColumnsButtonProps) => {
103103
transformOrigin={isRtl ? RTL_ORIGIN : LTR_ORIGIN}
104104
>
105105
{/* ColumnsSelector will be rendered here via Portal */}
106-
<MenuList
107-
sx={{ px: 1, my: 0, minWidth: 200 }}
106+
<Box
108107
id={`${storeKey}-columnsSelector`}
108+
sx={{ px: 1, my: 0, minWidth: 200 }}
109109
/>
110110
</Popover>
111111
</Root>

packages/ra-ui-materialui/src/list/datatable/ColumnsSelector.tsx

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useTranslate,
99
DataTableColumnFilterContext,
1010
} from 'ra-core';
11-
import { Box, InputAdornment } from '@mui/material';
11+
import { Box, InputAdornment, MenuList } from '@mui/material';
1212
import SearchIcon from '@mui/icons-material/Search';
1313

1414
import { Button } from '../../button';
@@ -67,34 +67,36 @@ export const ColumnsSelector = ({ children }: ColumnsSelectorProps) => {
6767
const shouldDisplaySearchInput = childrenArray.length > 5;
6868

6969
return createPortal(
70-
<>
70+
<MenuList>
7171
{shouldDisplaySearchInput ? (
72-
<ResettableTextField
73-
hiddenLabel
74-
label=""
75-
value={columnFilter}
76-
onChange={e => {
77-
if (typeof e === 'string') {
78-
setColumnFilter(e);
79-
return;
80-
}
81-
setColumnFilter(e.target.value);
82-
}}
83-
placeholder={translate('ra.action.search_columns', {
84-
_: 'Search columns',
85-
})}
86-
InputProps={{
87-
endAdornment: (
88-
<InputAdornment position="end">
89-
<SearchIcon color="disabled" />
90-
</InputAdornment>
91-
),
92-
}}
93-
resettable
94-
autoFocus
95-
size="small"
96-
sx={{ mb: 1 }}
97-
/>
72+
<Box component="li" tabIndex={-1}>
73+
<ResettableTextField
74+
hiddenLabel
75+
label=""
76+
value={columnFilter}
77+
onChange={e => {
78+
if (typeof e === 'string') {
79+
setColumnFilter(e);
80+
return;
81+
}
82+
setColumnFilter(e.target.value);
83+
}}
84+
placeholder={translate('ra.action.search_columns', {
85+
_: 'Search columns',
86+
})}
87+
InputProps={{
88+
endAdornment: (
89+
<InputAdornment position="end">
90+
<SearchIcon color="disabled" />
91+
</InputAdornment>
92+
),
93+
}}
94+
resettable
95+
autoFocus
96+
size="small"
97+
sx={{ mb: 1 }}
98+
/>
99+
</Box>
98100
) : null}
99101
{paddedColumnRanks.map((position, index) => (
100102
<DataTableColumnRankContext.Provider
@@ -123,7 +125,7 @@ export const ColumnsSelector = ({ children }: ColumnsSelectorProps) => {
123125
Reset
124126
</Button>
125127
</Box>
126-
</>,
128+
</MenuList>,
127129
container
128130
);
129131
};

0 commit comments

Comments
 (0)