Skip to content

Commit bb7ab82

Browse files
committed
Fix <ColumnsButton> cannot be used with keyboard
1 parent 09d3bb4 commit bb7ab82

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import * as React from 'react';
22
import { useTranslate, useResourceContext } from 'ra-core';
33
import {
4-
Box,
54
Button,
65
type ButtonProps,
7-
Menu,
86
useMediaQuery,
97
Theme,
108
Tooltip,
119
IconButton,
10+
Popover,
11+
MenuList,
12+
PopoverOrigin,
1213
} from '@mui/material';
14+
import { useRtl } from '@mui/system/RtlProvider';
1315
import ViewWeekIcon from '@mui/icons-material/ViewWeek';
1416
import {
1517
type ComponentsOverrides,
@@ -49,7 +51,7 @@ export const ColumnsButton = (inProps: ColumnsButtonProps) => {
4951
const storeKey = props.storeKey || `${resource}.datatable`;
5052

5153
const [anchorEl, setAnchorEl] = React.useState(null);
52-
54+
const isRtl = useRtl();
5355
const translate = useTranslate();
5456
const isXSmall = useMediaQuery((theme: Theme) =>
5557
theme.breakpoints.down('sm')
@@ -89,23 +91,37 @@ export const ColumnsButton = (inProps: ColumnsButtonProps) => {
8991
{title}
9092
</Button>
9193
)}
92-
<Menu
94+
<Popover
9395
open={Boolean(anchorEl)}
9496
keepMounted
9597
anchorEl={anchorEl}
9698
onClose={handleClose}
99+
anchorOrigin={{
100+
vertical: 'bottom',
101+
horizontal: isRtl ? 'right' : 'left',
102+
}}
103+
transformOrigin={isRtl ? RTL_ORIGIN : LTR_ORIGIN}
97104
>
98105
{/* ColumnsSelector will be rendered here via Portal */}
99-
<Box
100-
component="ul"
106+
<MenuList
101107
sx={{ px: 1, my: 0, minWidth: 200 }}
102108
id={`${storeKey}-columnsSelector`}
103109
/>
104-
</Menu>
110+
</Popover>
105111
</Root>
106112
);
107113
};
108114

115+
const RTL_ORIGIN: PopoverOrigin = {
116+
vertical: 'top',
117+
horizontal: 'right',
118+
};
119+
120+
const LTR_ORIGIN: PopoverOrigin = {
121+
vertical: 'top',
122+
horizontal: 'left',
123+
};
124+
109125
const PREFIX = 'RaColumnsButton';
110126
const Root = styled('span', {
111127
name: PREFIX,

packages/ra-ui-materialui/src/preferences/FieldToggle.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const FieldToggle = (props: FieldToggleProps) => {
102102
return (
103103
<Root
104104
key={source}
105+
role="option"
105106
draggable={onMove ? 'true' : undefined}
106107
onDrag={onMove ? handleDrag : undefined}
107108
onDragStart={onMove ? handleDragStart : undefined}

0 commit comments

Comments
 (0)