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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data grid] Grid doesn't scroll horizontally during column reorder #6236

Closed
2 tasks done
cherniavskii opened this issue Sep 21, 2022 · 1 comment 路 Fixed by #8856
Closed
2 tasks done

[data grid] Grid doesn't scroll horizontally during column reorder #6236

cherniavskii opened this issue Sep 21, 2022 · 1 comment 路 Fixed by #8856
Labels
bug 馃悰 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Reordering Related to the data grid Reordering feature regression A bug, but worse

Comments

@cherniavskii
Copy link
Member

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 馃槸

Grid doesn't scroll horizontally when trying to reorder the column outside of currently visible columns:

Screen.Recording.2022-09-21.at.14.27.17.mov

Expected behavior 馃

Grid scrolls horizontally when trying to reorder the column outside of currently visible columns:

Steps to reproduce 馃暪

Link to live example:

Steps:

  1. Go to https://codesandbox.io/s/focused-bash-5089yf?file=/demo.tsx
  2. Start dragging a column to the right
  3. See that grid doesn't scroll horizontally preventing from moving a column outside of currently visible columns

Context 馃敠

Column reorder feature is only available in Pro and Premium plans.

There's GridScrollArea component that is supposed to handle the scroll

function GridScrollAreaRaw(props: ScrollAreaProps) {

But it's only used in DataGrid component:

<GridScrollArea scrollDirection="left" />
<GridColumnHeadersInner isDragging={isDragging} {...getInnerProps()}>
{getColumnGroupHeaders()}
{getColumnHeaders()}
</GridColumnHeadersInner>
<GridScrollArea scrollDirection="right" />

Instead of being used in DataGridPro and DataGridPremium components:

<GridColumnHeadersInner isDragging={isDragging} {...innerProps}>
{getColumnGroupHeaders({
renderContext,
minFirstColumn: leftPinnedColumns.length,
maxLastColumn: visibleColumnFields.length - rightPinnedColumns.length,
})}
{getColumnHeaders({
renderContext,
minFirstColumn: leftPinnedColumns.length,
maxLastColumn: visibleColumnFields.length - rightPinnedColumns.length,
})}
</GridColumnHeadersInner>

The diff below should do the job:

diff --git a/packages/grid/x-data-grid-pro/src/components/DataGridProColumnHeaders.tsx b/packages/gr
id/x-data-grid-pro/src/components/DataGridProColumnHeaders.tsx
index 6112388a96..153a7f02a8 100644
--- a/packages/grid/x-data-grid-pro/src/components/DataGridProColumnHeaders.tsx
+++ b/packages/grid/x-data-grid-pro/src/components/DataGridProColumnHeaders.tsx
@@ -9,6 +9,7 @@ import {
   useGridApiEventHandler,
   gridVisibleColumnFieldsSelector,
   GridColumnHeaderSeparatorSides,
+  GridScrollArea,
 } from '@mui/x-data-grid';
 import {
   GridColumnHeaders,
@@ -183,6 +184,7 @@ export const DataGridProColumnHeaders = React.forwardRef<
           )}
         </GridColumnHeadersPinnedColumnHeaders>
       )}
+      <GridScrollArea scrollDirection="left" />
       <GridColumnHeadersInner isDragging={isDragging} {...innerProps}>
         {getColumnGroupHeaders({
           renderContext,
@@ -195,6 +197,7 @@ export const DataGridProColumnHeaders = React.forwardRef<
           maxLastColumn: visibleColumnFields.length - rightPinnedColumns.length,
         })}
       </GridColumnHeadersInner>
+      <GridScrollArea scrollDirection="right" />
       {rightRenderContext && (
         <GridColumnHeadersPinnedColumnHeaders
           ownerState={{ side: GridPinnedPosition.right }}
diff --git a/packages/grid/x-data-grid/src/components/DataGridColumnHeaders.tsx b/packages/grid/x-da
ta-grid/src/components/DataGridColumnHeaders.tsx
index 0888cb7a3d..d2bd89b318 100644
--- a/packages/grid/x-data-grid/src/components/DataGridColumnHeaders.tsx
+++ b/packages/grid/x-data-grid/src/components/DataGridColumnHeaders.tsx
@@ -1,6 +1,5 @@
 import * as React from 'react';
 import { useGridColumnHeaders } from '../hooks/features/columnHeaders/useGridColumnHeaders';
-import { GridScrollArea } from './GridScrollArea';
 import { GridColumnHeaders } from './columnHeaders/GridColumnHeaders';
 import { GridColumnHeadersInner } from './columnHeaders/GridColumnHeadersInner';
 
@@ -19,12 +18,10 @@ export const DataGridColumnHeaders = React.forwardRef<HTMLDivElement, DataGridCo
 
     return (
       <GridColumnHeaders ref={ref} {...getRootProps(other)}>
-        <GridScrollArea scrollDirection="left" />
         <GridColumnHeadersInner isDragging={isDragging} {...getInnerProps()}>
           {getColumnGroupHeaders()}
           {getColumnHeaders()}
         </GridColumnHeadersInner>
-        <GridScrollArea scrollDirection="right" />
       </GridColumnHeaders>
     );
   },

Your environment 馃寧

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Order ID 馃挸 (optional)

No response

@cherniavskii cherniavskii added bug 馃悰 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Reordering Related to the data grid Reordering feature labels Sep 21, 2022
@oliviertassinari oliviertassinari added the regression A bug, but worse label Dec 1, 2022
@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 1, 2022

It's a regression, I recall @DanailH worked on it (and I a bit) at the very beginning #165.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 馃悰 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Reordering Related to the data grid Reordering feature regression A bug, but worse
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants