|
1 | 1 | import * as React from 'react';
|
2 | 2 | import { useTranslate, useResourceContext } from 'ra-core';
|
3 | 3 | import {
|
4 |
| - Box, |
5 | 4 | Button,
|
6 | 5 | type ButtonProps,
|
7 |
| - Menu, |
8 | 6 | useMediaQuery,
|
9 | 7 | Theme,
|
10 | 8 | Tooltip,
|
11 | 9 | IconButton,
|
| 10 | + Popover, |
| 11 | + MenuList, |
| 12 | + PopoverOrigin, |
12 | 13 | } from '@mui/material';
|
| 14 | +import { useRtl } from '@mui/system/RtlProvider'; |
13 | 15 | import ViewWeekIcon from '@mui/icons-material/ViewWeek';
|
14 | 16 | import {
|
15 | 17 | type ComponentsOverrides,
|
@@ -49,7 +51,7 @@ export const ColumnsButton = (inProps: ColumnsButtonProps) => {
|
49 | 51 | const storeKey = props.storeKey || `${resource}.datatable`;
|
50 | 52 |
|
51 | 53 | const [anchorEl, setAnchorEl] = React.useState(null);
|
52 |
| - |
| 54 | + const isRtl = useRtl(); |
53 | 55 | const translate = useTranslate();
|
54 | 56 | const isXSmall = useMediaQuery((theme: Theme) =>
|
55 | 57 | theme.breakpoints.down('sm')
|
@@ -89,23 +91,37 @@ export const ColumnsButton = (inProps: ColumnsButtonProps) => {
|
89 | 91 | {title}
|
90 | 92 | </Button>
|
91 | 93 | )}
|
92 |
| - <Menu |
| 94 | + <Popover |
93 | 95 | open={Boolean(anchorEl)}
|
94 | 96 | keepMounted
|
95 | 97 | anchorEl={anchorEl}
|
96 | 98 | onClose={handleClose}
|
| 99 | + anchorOrigin={{ |
| 100 | + vertical: 'bottom', |
| 101 | + horizontal: isRtl ? 'right' : 'left', |
| 102 | + }} |
| 103 | + transformOrigin={isRtl ? RTL_ORIGIN : LTR_ORIGIN} |
97 | 104 | >
|
98 | 105 | {/* ColumnsSelector will be rendered here via Portal */}
|
99 |
| - <Box |
100 |
| - component="ul" |
| 106 | + <MenuList |
101 | 107 | sx={{ px: 1, my: 0, minWidth: 200 }}
|
102 | 108 | id={`${storeKey}-columnsSelector`}
|
103 | 109 | />
|
104 |
| - </Menu> |
| 110 | + </Popover> |
105 | 111 | </Root>
|
106 | 112 | );
|
107 | 113 | };
|
108 | 114 |
|
| 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 | + |
109 | 125 | const PREFIX = 'RaColumnsButton';
|
110 | 126 | const Root = styled('span', {
|
111 | 127 | name: PREFIX,
|
|
0 commit comments