Skip to content

Commit

Permalink
Add scroll fixes to DataGrid skeleton loading (#3257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Feb 27, 2024
1 parent f0478cf commit 2664c1e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/toolpad-components/src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,29 @@ function SkeletonLoadingOverlay() {

const rowsCount = apiRef.current.getRowsCount();

const scrollRef = React.useRef<HTMLDivElement>(null);

React.useEffect(() => {
// The `subscribeEvent` method will automatically unsubscribe in the cleanup function of the `useEffect`.
return apiRef.current.subscribeEvent('scrollPositionChange', (params) => {
if (scrollRef.current) {
scrollRef.current.scrollLeft = params.left;
}
});
}, [apiRef]);

return rowsCount > 0 ? (
<LinearProgress />
) : (
<div
ref={scrollRef}
style={{
display: 'grid',
gridTemplateColumns: `${columns
.map(({ computedWidth }) => `${computedWidth}px`)
.join(' ')} 1fr`,
gridAutoRows: `${rowHeight}px`,
overflowX: 'hidden',
}}
>
{children}
Expand Down

0 comments on commit 2664c1e

Please sign in to comment.