Skip to content

Commit

Permalink
update width when there is a resize
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw committed Oct 8, 2021
1 parent a43edb1 commit 6035ae6
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,20 @@ export const GridColumnsHeader = React.forwardRef<HTMLDivElement, any>(function
return columns;
};

React.useEffect(() => {
const updateWidth = React.useCallback(() => {
const newWidth = Math.max(
apiRef.current.columnHeadersContainerElementRef?.current?.clientWidth || 0,
columnsMeta.totalWidth,
);
setWidth(newWidth);
}, [apiRef, columnsMeta.totalWidth]);

const handleResize = React.useCallback(() => {
updateWidth();
}, [updateWidth]);

useGridApiEventHandler(apiRef, GridEvents.resize, handleResize);

return (
<Root style={{ width }}>
<div
Expand Down

0 comments on commit 6035ae6

Please sign in to comment.