-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGrid] Column menu visual updates #8424
Changes from 8 commits
ef48445
d9696a0
8993b38
39dd471
ef94a5e
2920fb2
3f7d3c1
ef12f16
71038a3
bda19e7
1c7a05d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { GridColumnMenuItemProps, useGridSelector } from '@mui/x-data-grid-pro'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import MUIMenuItem from '@mui/material/MenuItem'; | ||
import ListItemIcon from '@mui/material/ListItemIcon'; | ||
import ListItemText from '@mui/material/ListItemText'; | ||
import FormControl from '@mui/material/FormControl'; | ||
import InputLabel from '@mui/material/InputLabel'; | ||
import { unstable_useId as useId } from '@mui/utils'; | ||
import Select, { SelectChangeEvent } from '@mui/material/Select'; | ||
import type { SelectChangeEvent } from '@mui/material/Select'; | ||
import { styled } from '@mui/material/styles'; | ||
import { useGridApiContext } from '../hooks/utils/useGridApiContext'; | ||
import { useGridRootProps } from '../hooks/utils/useGridRootProps'; | ||
import { | ||
|
@@ -18,6 +18,22 @@ import { | |
import { gridAggregationModelSelector } from '../hooks/features/aggregation/gridAggregationSelectors'; | ||
import { GridAggregationModel } from '../hooks/features/aggregation/gridAggregationInterfaces'; | ||
|
||
const MenuItem = styled(MUIMenuItem)(() => ({ | ||
'&:hover': { | ||
backgroundColor: 'transparent', | ||
}, | ||
'& .MuiFormControl-root': { | ||
minWidth: 150, | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
'& button': { | ||
padding: 2, | ||
marginLeft: 4, | ||
}, | ||
})); | ||
|
||
function GridColumnMenuAggregationItem(props: GridColumnMenuItemProps) { | ||
const { colDef } = props; | ||
const apiRef = useGridApiContext(); | ||
|
@@ -74,32 +90,36 @@ function GridColumnMenuAggregationItem(props: GridColumnMenuItemProps) { | |
<rootProps.slots.columnMenuAggregationIcon fontSize="small" /> | ||
</ListItemIcon> | ||
<ListItemText> | ||
<FormControl size="small" fullWidth sx={{ minWidth: 150 }}> | ||
<rootProps.slots.baseFormControl size="small" fullWidth> | ||
<InputLabel id={`${id}-label`}>{label}</InputLabel> | ||
<Select | ||
<rootProps.slots.baseSelect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
aria-labelledby={`${id}-label`} | ||
labelId={`${id}-label`} | ||
id={`${id}-input`} | ||
value={selectedAggregationRule} | ||
label={label} | ||
color="primary" | ||
onChange={handleAggregationItemChange} | ||
onBlur={(e) => e.stopPropagation()} | ||
onBlur={(e: FocusEvent) => e.stopPropagation()} | ||
fullWidth | ||
> | ||
<MenuItem value="">...</MenuItem> | ||
{availableAggregationFunctions.map((aggFunc) => ( | ||
<MenuItem key={aggFunc} value={aggFunc}> | ||
<rootProps.slots.baseSelectOption key={aggFunc} value={aggFunc}> | ||
{getAggregationFunctionLabel({ | ||
apiRef, | ||
aggregationRule: { | ||
aggregationFunctionName: aggFunc, | ||
aggregationFunction: rootProps.aggregationFunctions[aggFunc], | ||
}, | ||
})} | ||
</MenuItem> | ||
</rootProps.slots.baseSelectOption> | ||
))} | ||
</Select> | ||
</FormControl> | ||
</rootProps.slots.baseSelect> | ||
{selectedAggregationRule ? ( | ||
<rootProps.slots.baseIconButton onClick={handleAggregationItemChange}> | ||
<rootProps.slots.columnMenuClearIcon fontSize="small" color="action" /> | ||
</rootProps.slots.baseIconButton> | ||
) : null} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the clear icon be part of the text field? It sounds more like an external element, it's rendered outside of the input. Off-topic. I wonder if we wouldn't want to move toward removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, making it part of the text field would make it feel a bit better.
Do you mean native input/select components? I feel currently we are going in the other direction, by adding slots for all possible components for them to be able to be swapped between Material/Joy UI/any future design system's components. I can't picture how a developer will add their custom design system on top if we replace these items with the native input/select. |
||
</rootProps.slots.baseFormControl> | ||
</ListItemText> | ||
</MenuItem> | ||
); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,7 +9,9 @@ import { GridColumnMenuContainerProps } from './GridColumnMenuProps'; | |||||
import { gridClasses } from '../../../constants/gridClasses'; | ||||||
|
||||||
const StyledMenuList = styled(MenuList)(() => ({ | ||||||
minWidth: 248, | ||||||
'@media (pointer: fine)': { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that the constraint is on whether the primary pointer is fine (e.g. cursor) or not (e.g. touch screen). It feels like it's more a problem with screen width, so
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, I think the same is done in MUI MenuList. |
||||||
minWidth: 248, | ||||||
}, | ||||||
})); | ||||||
|
||||||
const GridColumnMenuContainer = React.forwardRef<HTMLUListElement, GridColumnMenuContainerProps>( | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pointer cursor feels strange, it signals that I can click but clicking doesn't do anything:
Screen.Recording.2023-05-31.at.15.29.43.mov
So either:
or we wire the click to focus the select and open it.
Off-topic. The MenuItem component might need a mode where it's only here to handle consistent spacing but not have any actions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a default cursor.
Yes, I guess that could be a useful mode to handle more use-cases like this.