Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Oct 19, 2020
1 parent 5ca3722 commit 9ed7b17
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/grid/_modules_/grid/components/AutoSizer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { useForkRef, ownerWindow, useEventCallback } from '@material-ui/core/utils';
import { useForkRef, ownerWindow } from '@material-ui/core/utils';
import { useEventCallback } from '../utils/material-ui-utils';
import createDetectElementResize from '../lib/createDetectElementResize';
// TODO replace with https://caniuse.com/resizeobserver.

Expand Down Expand Up @@ -118,7 +119,6 @@ export const AutoSizer = React.forwardRef<HTMLDivElement, AutoSizerProps>(functi

const detectElementResize = createDetectElementResize(nonce, win);
detectElementResize.addResizeListener(parentElement.current, handleResize);
// @ts-expect-error fixed in v5
handleResize();

return () => {
Expand Down
14 changes: 4 additions & 10 deletions packages/grid/_modules_/grid/hooks/features/useColumnResize.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { useEventCallback, ownerDocument } from '@material-ui/core/utils';
import { ownerDocument } from '@material-ui/core/utils';
import { ColDef } from '../../models/colDef';
import { useLogger } from '../utils';
import { useEventCallback } from '../../utils/material-ui-utils';
import { COL_RESIZE_START, COL_RESIZE_STOP } from '../../constants/eventsConstants';
import { HEADER_CELL_CSS_CLASS } from '../../constants/cssClassesConstants';
import { findCellElementsFromCol } from '../../utils';
Expand Down Expand Up @@ -53,8 +54,7 @@ export const useColumnResize = (columnsRef: React.RefObject<HTMLDivElement>, api
const handleResizeMouseMove = useEventCallback((nativeEvent) => {
// Cancel move in case some other element consumed a mouseup event and it was not fired.
if (nativeEvent.buttons === 0) {
// @ts-expect-error fixed in v5
handleResizeMouseUp(nativeEvent);
handleResizeMouseUp();
return;
}

Expand Down Expand Up @@ -105,18 +105,14 @@ export const useColumnResize = (columnsRef: React.RefObject<HTMLDivElement>, api
(colDefRef.current.width as number) -
(event.clientX - colElementRef.current!.getBoundingClientRect().left);

// @ts-expect-error fixed in v5
doc.addEventListener('mousemove', handleResizeMouseMove);
// @ts-expect-error fixed in v5
doc.addEventListener('mouseup', handleResizeMouseUp);
});

const stopListening = React.useCallback(() => {
const doc = ownerDocument(apiRef.current.rootElementRef!.current as HTMLElement);
doc.body.style.removeProperty('cursor');
// @ts-expect-error fixed in v5
doc.removeEventListener('mousemove', handleResizeMouseMove);
// @ts-expect-error fixed in v5
doc.removeEventListener('mouseup', handleResizeMouseUp);
}, [apiRef, handleResizeMouseMove, handleResizeMouseUp]);

Expand All @@ -127,7 +123,5 @@ export const useColumnResize = (columnsRef: React.RefObject<HTMLDivElement>, api
};
}, [stopListening]);

return React.useMemo(() => ({ onMouseDown: handleMouseDown }), [
handleMouseDown,
]) as React.HTMLAttributes<HTMLDivElement>;
return React.useMemo(() => ({ onMouseDown: handleMouseDown }), [handleMouseDown]);
};
6 changes: 6 additions & 0 deletions packages/grid/_modules_/grid/utils/material-ui-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useEventCallback as muiUseEventCallback } from '@material-ui/core/utils';

export function useEventCallback<T extends (...args: any[]) => any>(func: T): T {
// @ts-expect-error TODO remove wrapper once upgraded to v5
return muiUseEventCallback(func);
}

0 comments on commit 9ed7b17

Please sign in to comment.