Skip to content
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] Fix error logged during skeleton loading with nested data grid #14186

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ const GridSkeletonLoadingOverlay = React.forwardRef<
}

if (hasScrollbarFiller) {
rowCells.push(<GridScrollbarFillerCell pinnedRight={pinnedColumns.right.length > 0} />);
rowCells.push(
<GridScrollbarFillerCell
key={`skeleton-scrollbar-filler-${i}`}
pinnedRight={pinnedColumns.right.length > 0}
/>,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,6 @@ export const GridRootStyles = styled('div', {
[`& .${c['filler--borderTop']}`]: {
borderTop: '1px solid var(--DataGrid-rowBorderColor)',
},

/* Hide grid rows and vertical scrollbar when skeleton overlay is visible */
[`& .${c['main--hasSkeletonLoadingOverlay']}`]: {
[`& .${c.virtualScrollerContent}, & .${c['scrollbar--vertical']}, & .${c.pinnedRows}`]: {
display: 'none',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing this instead:

visibility: 'hidden',
position: 'fixed',

It seems to work, but I'm unsure if this would work in every scenario.
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem to work - I thought we tried this the other day 😅. I will do some more thorough testing to double check different scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the ideal combination here. The virtual scroller content retains it's height with visibility: hidden, fixing the issue with nested data grid. And position: fixed takes the element out of the flow. Will make the change, thanks @cherniavskii for taking a look.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 🎉

},
},
};

return gridStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,14 @@ import { GridVirtualScrollerContent as Content } from './GridVirtualScrollerCont
import { GridVirtualScrollerFiller as SpaceFiller } from './GridVirtualScrollerFiller';
import { GridVirtualScrollerRenderZone as RenderZone } from './GridVirtualScrollerRenderZone';
import { GridVirtualScrollbar as Scrollbar } from './GridVirtualScrollbar';
import { GridLoadingOverlayVariant } from '../GridLoadingOverlay';

type OwnerState = DataGridProcessedProps;

const useUtilityClasses = (
ownerState: OwnerState,
dimensions: GridDimensions,
loadingOverlayVariant: GridLoadingOverlayVariant | null,
) => {
const useUtilityClasses = (ownerState: OwnerState, dimensions: GridDimensions) => {
const { classes } = ownerState;

const slots = {
root: [
'main',
dimensions.rightPinnedWidth > 0 && 'main--hasPinnedRight',
loadingOverlayVariant === 'skeleton' && 'main--hasSkeletonLoadingOverlay',
],
root: ['main', dimensions.rightPinnedWidth > 0 && 'main--hasPinnedRight'],
scroller: ['virtualScroller'],
};

Expand Down Expand Up @@ -72,7 +63,8 @@ function GridVirtualScroller(props: GridVirtualScrollerProps) {
const rootProps = useGridRootProps();
const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
const overlaysProps = useGridOverlays();
const classes = useUtilityClasses(rootProps, dimensions, overlaysProps.loadingOverlayVariant);
const classes = useUtilityClasses(rootProps, dimensions);
const hasSkeletonLoader = overlaysProps.loadingOverlayVariant === 'skeleton';

const virtualScroller = useGridVirtualScroller();
const {
Expand All @@ -99,20 +91,26 @@ function GridVirtualScroller(props: GridVirtualScrollerProps) {

<Overlays {...overlaysProps} />

<Content {...getContentProps()}>
<RenderZone {...getRenderZoneProps()}>
{rows}
{<rootProps.slots.detailPanels virtualScroller={virtualScroller} />}
</RenderZone>
</Content>
{!hasSkeletonLoader && (
<React.Fragment>
<Content {...getContentProps()}>
<RenderZone {...getRenderZoneProps()}>
{rows}
{<rootProps.slots.detailPanels virtualScroller={virtualScroller} />}
</RenderZone>
</Content>

<SpaceFiller rowsLength={rows.length} />
<SpaceFiller rowsLength={rows.length} />
</React.Fragment>
)}

<BottomContainer>
<rootProps.slots.pinnedRows position="bottom" virtualScroller={virtualScroller} />
</BottomContainer>
</Scroller>
{dimensions.hasScrollY && <Scrollbar position="vertical" {...getScrollbarVerticalProps()} />}
{dimensions.hasScrollY && !hasSkeletonLoader && (
<Scrollbar position="vertical" {...getScrollbarVerticalProps()} />
)}
{dimensions.hasScrollX && (
<Scrollbar position="horizontal" {...getScrollbarHorizontalProps()} />
)}
Expand Down
6 changes: 0 additions & 6 deletions packages/x-data-grid/src/constants/gridClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,6 @@ export interface GridClasses {
* Styles applied to the main container element when it has right pinned columns.
*/
'main--hasPinnedRight': string;
/**
* Styles applied to the main container element when it has an active skeleton loading overlay.
* @ignore - do not document.
*/
'main--hasSkeletonLoadingOverlay': string;
/**
* Styles applied to the menu element.
*/
Expand Down Expand Up @@ -725,7 +720,6 @@ export const gridClasses = generateUtilityClasses<GridClassKey>('MuiDataGrid', [
'iconSeparator',
'main',
'main--hasPinnedRight',
'main--hasSkeletonLoadingOverlay',
'menu',
'menuIcon',
'menuIconButton',
Expand Down
Loading