-
-
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
[DataGridPro] Fix column pinning layout #14966
Merged
cherniavskii
merged 11 commits into
mui:master
from
cherniavskii:fix-column-pinning-filler
Oct 23, 2024
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d4aedbb
make filler grow and fill available space
cherniavskii 41ca1d5
fix overlay height
cherniavskii 719479e
Merge branch 'master' into fix-column-pinning-filler
cherniavskii 9c21841
remove unnecessary offset for bottom container
cherniavskii 4a982cf
add regression demo
cherniavskii 7f97a3d
fix unit tests
cherniavskii 7d2224c
fix more unit tests
cherniavskii debda11
fix unit test
cherniavskii 991912c
fix flaky screenshot
cherniavskii 849d329
Revert "fix flaky screenshot"
cherniavskii 71cdfe6
skip tests asserting computed styles in jsdom
cherniavskii 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
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
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 |
---|---|---|
|
@@ -3,9 +3,6 @@ import clsx from 'clsx'; | |
import { styled } from '@mui/system'; | ||
import composeClasses from '@mui/utils/composeClasses'; | ||
import { gridClasses, getDataGridUtilityClass } from '../../constants/gridClasses'; | ||
import { gridDimensionsSelector } from '../../hooks/features/dimensions/gridDimensionsSelectors'; | ||
import { useGridApiContext } from '../../hooks/utils/useGridApiContext'; | ||
import { useGridSelector } from '../../hooks/utils/useGridSelector'; | ||
|
||
const useUtilityClasses = () => { | ||
const slots = { | ||
|
@@ -23,25 +20,10 @@ const Element = styled('div')({ | |
export function GridBottomContainer(props: React.PropsWithChildren) { | ||
const classes = useUtilityClasses(); | ||
|
||
const apiRef = useGridApiContext(); | ||
const { viewportOuterSize, minimumSize, hasScrollX, scrollbarSize } = useGridSelector( | ||
apiRef, | ||
gridDimensionsSelector, | ||
); | ||
const scrollHeight = hasScrollX ? scrollbarSize : 0; | ||
const offset = Math.max( | ||
viewportOuterSize.height - | ||
minimumSize.height - | ||
// Subtract scroll height twice to account for GridVirtualScrollerFiller and horizontal scrollbar | ||
2 * scrollHeight, | ||
0, | ||
); | ||
|
||
return ( | ||
<Element | ||
{...props} | ||
className={clsx(classes.root, gridClasses['container--bottom'])} | ||
style={{ transform: `translateY(${offset}px)` }} | ||
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. No need for that because filler now grows |
||
role="presentation" | ||
/> | ||
); | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as React from 'react'; | ||
import DeleteIcon from '@mui/icons-material/Delete'; | ||
import EditIcon from '@mui/icons-material/Edit'; | ||
import { DataGridPro, GridActionsCellItem } from '@mui/x-data-grid-pro'; | ||
import { | ||
randomCreatedDate, | ||
randomTraderName, | ||
randomEmail, | ||
randomUpdatedDate, | ||
} from '@mui/x-data-grid-generator'; | ||
|
||
const columns = [ | ||
{ field: 'name', headerName: 'Name', width: 160, editable: true }, | ||
{ field: 'email', headerName: 'Email', width: 200, editable: true }, | ||
{ field: 'age', headerName: 'Age', type: 'number', editable: true }, | ||
{ | ||
field: 'dateCreated', | ||
headerName: 'Date Created', | ||
type: 'date', | ||
width: 180, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'lastLogin', | ||
headerName: 'Last Login', | ||
type: 'dateTime', | ||
width: 220, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'actions', | ||
type: 'actions', | ||
width: 100, | ||
getActions: () => [ | ||
<GridActionsCellItem icon={<EditIcon />} label="Edit" />, | ||
<GridActionsCellItem icon={<DeleteIcon />} label="Delete" />, | ||
], | ||
}, | ||
]; | ||
|
||
const rows = [ | ||
{ | ||
id: 1, | ||
name: randomTraderName(), | ||
email: randomEmail(), | ||
age: 25, | ||
dateCreated: randomCreatedDate(), | ||
lastLogin: randomUpdatedDate(), | ||
}, | ||
]; | ||
|
||
export default function BasicColumnPinning() { | ||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
rows={rows} | ||
columns={columns} | ||
initialState={{ pinnedColumns: { left: ['name'], right: ['actions'] } }} | ||
/> | ||
</div> | ||
); | ||
} |
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.
I changed
height
toflex-basis
in /~https://github.com/mui/mui-x/pull/14966/files#diff-74adfff8c7dc341a80f5a489eb850b9d566b1be041dfdf0e47a9848609f5ac53R537, and I makes more sense to check the actual height rather than specific inline style.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.
Comment not specific to this in particular, but I feel like we often test the implementation too closely, e.g. we set a specific style and test for that style. Quite a few of our tests would be better as visual regression tests, they would be more resilient to implementation changes, and would catch actual regressions (like this one could have been caught if we had the visual regression test).
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.
Agreed, that's why I added a visual regression test for this one: /~https://github.com/mui/mui-x/pull/14966/files#diff-48fe2988003e6e416aaaed7d91bfb330c9f5d2b405f13244b9993e87a74b15de