-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Closed
MBilalShafi
wants to merge
11
commits into
mui:v6.x
from
MBilalShafi:fix-aggregation-item-column-menu
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ef48445
[DataGrid] Fix aggregation item causes the body scroll to jump
MBilalShafi d9696a0
Explore a solution with native select
MBilalShafi 8993b38
Remove width constraint on mobile devices
MBilalShafi 39dd471
Use baseSelect and fix tests
MBilalShafi ef94a5e
Remove dangling .only
MBilalShafi 2920fb2
Re-run CI
MBilalShafi 3f7d3c1
Merge branch 'master' into fix-aggregation-item-column-menu
MBilalShafi ef12f16
Improve column menu aggregation item
MBilalShafi 71038a3
Merge branch 'master' into fix-aggregation-item-column-menu
MBilalShafi bda19e7
Olivier's feedback
MBilalShafi 1c7a05d
Fix test
MBilalShafi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
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 { styled } from '@mui/material/styles'; | ||
import { useGridApiContext } from '../hooks/utils/useGridApiContext'; | ||
import { useGridRootProps } from '../hooks/utils/useGridRootProps'; | ||
import { | ||
|
@@ -18,6 +17,39 @@ import { | |
import { gridAggregationModelSelector } from '../hooks/features/aggregation/gridAggregationSelectors'; | ||
import { GridAggregationModel } from '../hooks/features/aggregation/gridAggregationInterfaces'; | ||
|
||
const MenuItem = styled(MUIMenuItem)(() => ({ | ||
cursor: 'default', | ||
'&:hover': { | ||
backgroundColor: 'transparent', | ||
}, | ||
'& .MuiFormControl-root': { | ||
minWidth: 150, | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
'& button': { | ||
padding: 2, | ||
marginLeft: 4, | ||
}, | ||
})); | ||
|
||
const iconSx = { marginRight: 1.5 }; | ||
|
||
function ClearIcon({ | ||
handleChange, | ||
}: { | ||
handleChange: (event: { target: { value: string } }) => void; | ||
}) { | ||
const rootProps = useGridRootProps(); | ||
|
||
return ( | ||
<rootProps.slots.baseIconButton sx={iconSx} onClick={handleChange}> | ||
<rootProps.slots.columnMenuClearIcon fontSize="small" color="action" /> | ||
</rootProps.slots.baseIconButton> | ||
); | ||
} | ||
|
||
function GridColumnMenuAggregationItem(props: GridColumnMenuItemProps) { | ||
const { colDef } = props; | ||
const apiRef = useGridApiContext(); | ||
|
@@ -53,7 +85,7 @@ function GridColumnMenuAggregationItem(props: GridColumnMenuItemProps) { | |
return ''; | ||
}, [rootProps.aggregationFunctions, aggregationModel, colDef]); | ||
|
||
const handleAggregationItemChange = (event: SelectChangeEvent<string | undefined>) => { | ||
const handleAggregationItemChange = (event: { target: { value: string } }) => { | ||
const newAggregationItem = event.target?.value || undefined; | ||
const currentModel = gridAggregationModelSelector(apiRef); | ||
const { [colDef.field]: columnItem, ...otherColumnItems } = currentModel; | ||
|
@@ -74,32 +106,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()} | ||
endAdornment={ | ||
selectedAggregationRule ? ( | ||
<ClearIcon handleChange={handleAggregationItemChange} /> | ||
) : null | ||
} | ||
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> | ||
</rootProps.slots.baseFormControl> | ||
</ListItemText> | ||
</MenuItem> | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.