Skip to content

Commit

Permalink
[DataGrid] Rename rowsScroll event to scrollPositionChange (#6957)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanailH committed Nov 24, 2022
1 parent b673ec1 commit a6c96b3
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions docs/data/data-grid/events/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,6 @@
"params": "GridRowSelectionCheckboxParams",
"event": "MuiEvent<React.ChangeEvent<HTMLElement>>"
},
{
"projects": ["x-data-grid", "x-data-grid-pro", "x-data-grid-premium"],
"name": "rowsScroll",
"description": "Fired during the scroll of the grid viewport.",
"params": "GridScrollParams",
"event": "MuiEvent<React.UIEvent | MuiBaseEvent>"
},
{
"projects": ["x-data-grid-pro", "x-data-grid-premium"],
"name": "rowsScrollEnd",
Expand All @@ -374,6 +367,13 @@
"event": "MuiEvent<{}>",
"componentProp": "onRowsScrollEnd"
},
{
"projects": ["x-data-grid", "x-data-grid-pro", "x-data-grid-premium"],
"name": "scrollPositionChange",
"description": "Fired during the scroll of the grid viewport.",
"params": "GridScrollParams",
"event": "MuiEvent<React.UIEvent | MuiBaseEvent>"
},
{
"projects": ["x-data-grid", "x-data-grid-pro", "x-data-grid-premium"],
"name": "sortModelChange",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The minimum supported Node.js version has been changed from 12.0.0 to 14.0.0, si
### Events

- The `selectionChange` event was renamed to `rowSelectionChange`.
- The `rowsScroll` event was renamed to `scrollPositionChange`.
- The `columnVisibilityChange` event was removed. Use `columnVisibilityModelChange` instead.
- The `cellNavigationKeyDown` event was removed. Use `cellKeyDown` and check the key provided in the event argument.
- The `columnHeaderNavigationKeyDown` event was removed. Use `columnHeaderKeyDown` and check the key provided in the event argument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ export const useGridInfiniteLoader = (
],
);

const handleGridScroll = React.useCallback<GridEventListener<'rowsScroll'>>(
const handleGridScroll = React.useCallback<GridEventListener<'scrollPositionChange'>>(
({ left, top }) => {
handleRowsScrollEnd({ left, top });
},
[handleRowsScrollEnd],
);

useGridApiEventHandler(apiRef, 'rowsScroll', handleGridScroll);
useGridApiEventHandler(apiRef, 'scrollPositionChange', handleGridScroll);
useGridApiOptionHandler(apiRef, 'rowsScrollEnd', props.onRowsScrollEnd);
};
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ describe('<DataGridPro /> - Events Params', () => {
it('publishing GRID_ROWS_SCROLL should call onRowsScrollEnd callback', () => {
const handleRowsScrollEnd = spy();
render(<TestEvents onRowsScrollEnd={handleRowsScrollEnd} />);
act(() => apiRef.current.publishEvent('rowsScroll', { left: 0, top: 3 * 52 }));
act(() => apiRef.current.publishEvent('scrollPositionChange', { left: 0, top: 3 * 52 }));
expect(handleRowsScrollEnd.callCount).to.equal(1);
});

Expand All @@ -351,7 +351,7 @@ describe('<DataGridPro /> - Events Params', () => {
rowCount={50}
/>,
);
act(() => apiRef.current.publishEvent('rowsScroll', { left: 0, top: 3 * 52 }));
act(() => apiRef.current.publishEvent('scrollPositionChange', { left: 0, top: 3 * 52 }));
expect(handleFetchRows.callCount).to.equal(1);
});

Expand Down
4 changes: 2 additions & 2 deletions packages/grid/x-data-grid/src/components/GridScrollArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function GridScrollAreaRaw(props: ScrollAreaProps) {
const ownerState = { ...props, classes: rootProps.classes };
const classes = useUtilityClasses(ownerState);

const handleScrolling = React.useCallback<GridEventListener<'rowsScroll'>>(
const handleScrolling = React.useCallback<GridEventListener<'scrollPositionChange'>>(
(newScrollPosition) => {
scrollPosition.current = newScrollPosition;
},
Expand Down Expand Up @@ -115,7 +115,7 @@ function GridScrollAreaRaw(props: ScrollAreaProps) {
setDragging((prevDragging) => !prevDragging);
}, []);

useGridApiEventHandler(apiRef, 'rowsScroll', handleScrolling);
useGridApiEventHandler(apiRef, 'scrollPositionChange', handleScrolling);
useGridApiEventHandler(apiRef, 'columnHeaderDragStart', toggleDragging);
useGridApiEventHandler(apiRef, 'columnHeaderDragEnd', toggleDragging);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const useGridColumnHeaders = (props: UseGridColumnHeadersProps) => {
}
}, [renderContext, updateInnerPosition]);

const handleScroll = React.useCallback<GridEventListener<'rowsScroll'>>(
const handleScroll = React.useCallback<GridEventListener<'scrollPositionChange'>>(
({ left, renderContext: nextRenderContext = null }, event) => {
if (!innerRef.current) {
return;
Expand Down Expand Up @@ -235,7 +235,7 @@ export const useGridColumnHeaders = (props: UseGridColumnHeadersProps) => {
useGridApiEventHandler(apiRef, 'columnHeaderDragStart', handleColumnReorderStart);
useGridApiEventHandler(apiRef, 'columnHeaderDragEnd', handleColumnReorderStop);

useGridApiEventHandler(apiRef, 'rowsScroll', handleScroll);
useGridApiEventHandler(apiRef, 'scrollPositionChange', handleScroll);

// Helper for computation common between getColumnHeaders and getColumnGroupHeaders
const getColumnsToRender = (params?: GetHeadersParams) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => {

const { top, left } = scrollPosition.current!;
const params = { top, left, renderContext: initialRenderContext };
apiRef.current.publishEvent('rowsScroll', params);
apiRef.current.publishEvent('scrollPositionChange', params);
}, [apiRef, computeRenderContext, containerWidth, updateRenderContext]);

const handleScroll = (event: React.UIEvent) => {
Expand Down Expand Up @@ -347,9 +347,8 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => {
bottomColumnsScrolledSincePreviousRender >= rootProps.columnThreshold ||
prevTotalWidth.current !== columnsTotalWidth;

// TODO v6: rename event to a wider name, it's not only fired for row scrolling
apiRef.current.publishEvent(
'rowsScroll',
'scrollPositionChange',
{
top: scrollTop,
left: scrollLeft,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export interface GridEventLookup
/**
* Fired during the scroll of the grid viewport.
*/
rowsScroll: { params: GridScrollParams; event: React.UIEvent | MuiBaseEvent };
scrollPositionChange: { params: GridScrollParams; event: React.UIEvent | MuiBaseEvent };
/**
* Fired when the content size used by the `GridVirtualScroller` changes.
* @ignore - do not document.
Expand Down

0 comments on commit a6c96b3

Please sign in to comment.