forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridColumnMenuContainer.tsx
More file actions
77 lines (68 loc) · 2.46 KB
/
GridColumnMenuContainer.tsx
File metadata and controls
77 lines (68 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import clsx from 'clsx';
import PropTypes from 'prop-types';
import * as React from 'react';
import { styled } from '@mui/material/styles';
import { forwardRef } from '@mui/x-internals/forwardRef';
import { isHideMenuKey } from '../../../utils/keyboardUtils';
import { NotRendered } from '../../../utils/assert';
import { gridClasses } from '../../../constants/gridClasses';
import { GridSlotProps } from '../../../models/gridSlotsComponent';
import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
import { GridColumnMenuContainerProps } from './GridColumnMenuProps';
const StyledMenuList = styled(NotRendered<GridSlotProps['baseMenuList']>)(() => ({
minWidth: 248,
}));
const GridColumnMenuContainer = forwardRef<HTMLUListElement, GridColumnMenuContainerProps>(
function GridColumnMenuContainer(props, ref) {
const { hideMenu, colDef, id, labelledby, className, children, open, ...other } = props;
const rootProps = useGridRootProps();
const handleListKeyDown = React.useCallback(
(event: React.KeyboardEvent) => {
if (event.key === 'Tab') {
event.preventDefault();
}
if (isHideMenuKey(event.key)) {
hideMenu(event);
}
},
[hideMenu],
);
const handleMenuScrollCapture = React.useCallback(
(event: React.WheelEvent | React.TouchEvent) => {
if (!event.currentTarget.contains(event.target as Node)) {
return;
}
event.stopPropagation();
},
[],
);
return (
<StyledMenuList
as={rootProps.slots.baseMenuList}
id={id}
className={clsx(gridClasses.menuList, className)}
aria-labelledby={labelledby}
onKeyDown={handleListKeyDown}
onWheel={handleMenuScrollCapture}
onTouchMove={handleMenuScrollCapture}
autoFocus={open}
{...other}
ref={ref}
>
{children}
</StyledMenuList>
);
},
);
GridColumnMenuContainer.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
colDef: PropTypes.object.isRequired,
hideMenu: PropTypes.func.isRequired,
id: PropTypes.string,
labelledby: PropTypes.string,
open: PropTypes.bool.isRequired,
} as any;
export { GridColumnMenuContainer };