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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump React #15255

Merged
merged 30 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
79a0cbf
Bump @types/react to ^18.3.5
renovate[bot] Sep 4, 2024
2c71612
fix Cell and Row props types
cherniavskii Sep 5, 2024
a689d8a
fix type errors in test files
cherniavskii Sep 5, 2024
46a0052
Merge remote-tracking branch 'mui/master' into renovate/react
cherniavskii Sep 5, 2024
9ee51e7
update lockfile
cherniavskii Sep 5, 2024
1c7a7d4
proptypes
cherniavskii Sep 5, 2024
13acded
proptypes
cherniavskii Sep 5, 2024
72d2eb7
lint
cherniavskii Sep 5, 2024
b162a8b
Extract `ExportMenuItem` components separately to have consistent `pr…
LukasTy Sep 6, 2024
e19eb7d
Fix usage and docs
LukasTy Sep 6, 2024
2f94d98
Merge branch 'master' into renovate/react
cherniavskii Sep 6, 2024
842561c
revert toolbar export type change
cherniavskii Sep 6, 2024
174433d
use theme augmentation
cherniavskii Sep 6, 2024
868a335
Merge remote-tracking branch 'upstream/master' into renovate/react
LukasTy Nov 1, 2024
5daff1e
Bump to latest `@types/react` version
LukasTy Nov 1, 2024
8b4fb9d
Possibly more correct children type
LukasTy Nov 1, 2024
4865bf1
Revert exporting
LukasTy Nov 1, 2024
b3dabe1
Fix too loose type causing `proptypes` randomness
LukasTy Nov 1, 2024
b26a822
Revert to a single `GridToolbarExport` file with fixed types to avoid…
LukasTy Nov 1, 2024
65e9d1f
Small tweaks
LukasTy Nov 1, 2024
602cb3a
Bump `@types/react-dom`
LukasTy Nov 4, 2024
ad494f8
Fix eslint
LukasTy Nov 4, 2024
43f59a3
Remove no longer needed as slot casting
LukasTy Nov 4, 2024
50ae593
Fix module augmentation
LukasTy Nov 4, 2024
88e7702
Merge remote-tracking branch 'upstream/master' into renovate/react
LukasTy Nov 11, 2024
f93c892
fix toolbar ts error
cherniavskii Nov 12, 2024
0b1e3cc
proptypes
cherniavskii Nov 12, 2024
00b586f
Merge branch 'master' into renovate/react
cherniavskii Nov 12, 2024
5a1cd23
fix build
cherniavskii Nov 12, 2024
6a86fe4
fix type export
cherniavskii Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions docs/data/data-grid/editing/FullFeaturedCrudGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ export default function FullFeaturedCrudGrid() {
onRowModesModelChange={handleRowModesModelChange}
onRowEditStop={handleRowEditStop}
processRowUpdate={processRowUpdate}
slots={{
toolbar: EditToolbar,
}}
slots={{ toolbar: EditToolbar }}
slotProps={{
toolbar: { setRows, setRowModesModel },
}}
Expand Down
20 changes: 10 additions & 10 deletions docs/data/data-grid/editing/FullFeaturedCrudGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
GridRowId,
GridRowModel,
GridRowEditStopReasons,
GridSlots,
GridSlotProps,
} from '@mui/x-data-grid';
import {
randomCreatedDate,
Expand Down Expand Up @@ -70,14 +70,16 @@ const initialRows: GridRowsProp = [
},
];

interface EditToolbarProps {
setRows: (newRows: (oldRows: GridRowsProp) => GridRowsProp) => void;
setRowModesModel: (
newModel: (oldModel: GridRowModesModel) => GridRowModesModel,
) => void;
declare module '@mui/x-data-grid' {
interface ToolbarPropsOverrides {
setRows: (newRows: (oldRows: GridRowsProp) => GridRowsProp) => void;
setRowModesModel: (
newModel: (oldModel: GridRowModesModel) => GridRowModesModel,
) => void;
}
}

function EditToolbar(props: EditToolbarProps) {
function EditToolbar(props: GridSlotProps['toolbar']) {
const { setRows, setRowModesModel } = props;

const handleClick = () => {
Expand Down Expand Up @@ -240,9 +242,7 @@ export default function FullFeaturedCrudGrid() {
onRowModesModelChange={handleRowModesModelChange}
onRowEditStop={handleRowEditStop}
processRowUpdate={processRowUpdate}
slots={{
toolbar: EditToolbar as GridSlots['toolbar'],
}}
slots={{ toolbar: EditToolbar }}
slotProps={{
toolbar: { setRows, setRowModesModel },
}}
Expand Down
4 changes: 1 addition & 3 deletions docs/data/data-grid/editing/FullFeaturedCrudGrid.tsx.preview
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
onRowModesModelChange={handleRowModesModelChange}
onRowEditStop={handleRowEditStop}
processRowUpdate={processRowUpdate}
slots={{
toolbar: EditToolbar as GridSlots['toolbar'],
}}
slots={{ toolbar: EditToolbar }}
slotProps={{
toolbar: { setRows, setRowModesModel },
}}
Expand Down
5 changes: 1 addition & 4 deletions docs/data/data-grid/editing/StartEditButtonGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,11 @@ export default function StartEditButtonGrid() {
cellModesModel={cellModesModel}
onCellEditStop={handleCellEditStop}
onCellModesModelChange={(model) => setCellModesModel(model)}
slots={{
toolbar: EditToolbar,
}}
slots={{ toolbar: EditToolbar }}
slotProps={{
toolbar: {
cellMode,
selectedCellParams,
setSelectedCellParams,
cellModesModel,
setCellModesModel,
},
Expand Down
21 changes: 10 additions & 11 deletions docs/data/data-grid/editing/StartEditButtonGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
GridCellModes,
GridEventListener,
GridCellModesModel,
GridSlots,
GridSlotProps,
} from '@mui/x-data-grid';
import {
randomCreatedDate,
Expand All @@ -22,14 +22,16 @@ interface SelectedCellParams {
field: string;
}

interface EditToolbarProps {
selectedCellParams?: SelectedCellParams;
cellModesModel: GridCellModesModel;
setCellModesModel: (value: GridCellModesModel) => void;
cellMode: 'view' | 'edit';
declare module '@mui/x-data-grid' {
interface ToolbarPropsOverrides {
selectedCellParams: SelectedCellParams | null;
cellModesModel: GridCellModesModel;
setCellModesModel: (value: GridCellModesModel) => void;
cellMode: 'view' | 'edit';
}
}

function EditToolbar(props: EditToolbarProps) {
function EditToolbar(props: GridSlotProps['toolbar']) {
const { selectedCellParams, cellMode, cellModesModel, setCellModesModel } = props;

const handleSaveOrEdit = () => {
Expand Down Expand Up @@ -147,14 +149,11 @@ export default function StartEditButtonGrid() {
cellModesModel={cellModesModel}
onCellEditStop={handleCellEditStop}
onCellModesModelChange={(model) => setCellModesModel(model)}
slots={{
toolbar: EditToolbar as GridSlots['toolbar'],
}}
slots={{ toolbar: EditToolbar }}
slotProps={{
toolbar: {
cellMode,
selectedCellParams,
setSelectedCellParams,
cellModesModel,
setCellModesModel,
},
Expand Down
8 changes: 2 additions & 6 deletions docs/data/data-grid/filtering/CustomFilterPanelPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ export default function CustomFilterPanelPosition() {
<div style={{ height: 400, width: '100%' }}>
<DataGrid
{...data}
slots={{
toolbar: CustomToolbar,
}}
slots={{ toolbar: CustomToolbar }}
slotProps={{
panel: {
anchorEl: filterButtonEl,
},
toolbar: {
setFilterButtonEl,
},
toolbar: { setFilterButtonEl },
}}
/>
</div>
Expand Down
20 changes: 10 additions & 10 deletions docs/data/data-grid/filtering/CustomFilterPanelPosition.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import * as React from 'react';
import {
DataGrid,
GridSlots,
GridSlotProps,
GridToolbarContainer,
GridToolbarFilterButton,
} from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

const VISIBLE_FIELDS = ['name', 'rating', 'country', 'dateCreated', 'isAdmin'];

interface CustomToolbarProps {
setFilterButtonEl: React.Dispatch<React.SetStateAction<HTMLButtonElement | null>>;
declare module '@mui/x-data-grid' {
interface ToolbarPropsOverrides {
setFilterButtonEl: React.Dispatch<
React.SetStateAction<HTMLButtonElement | null>
>;
}
}

function CustomToolbar({ setFilterButtonEl }: CustomToolbarProps) {
function CustomToolbar({ setFilterButtonEl }: GridSlotProps['toolbar']) {
return (
<GridToolbarContainer>
<GridToolbarFilterButton ref={setFilterButtonEl} />
Expand All @@ -35,16 +39,12 @@ export default function CustomFilterPanelPosition() {
<div style={{ height: 400, width: '100%' }}>
<DataGrid
{...data}
slots={{
toolbar: CustomToolbar as GridSlots['toolbar'],
}}
slots={{ toolbar: CustomToolbar }}
slotProps={{
panel: {
anchorEl: filterButtonEl,
},
toolbar: {
setFilterButtonEl,
},
toolbar: { setFilterButtonEl },
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<DataGrid
{...data}
slots={{
toolbar: CustomToolbar as GridSlots['toolbar'],
}}
slots={{ toolbar: CustomToolbar }}
slotProps={{
panel: {
anchorEl: filterButtonEl,
},
toolbar: {
setFilterButtonEl,
},
toolbar: { setFilterButtonEl },
}}
/>
9 changes: 9 additions & 0 deletions docs/data/data-grid/list-view/ListViewAdvanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ import { formatDate, formatSize, stringAvatar } from './utils';
import { ActionDrawer } from './components/ActionDrawer';
import { RenameDialog } from './components/RenameDialog';

declare module '@mui/x-data-grid' {
interface ToolbarPropsOverrides {
listView: boolean;
container: () => HTMLElement;
handleDelete: (ids: GridRowId[]) => void;
handleUpload: (event: React.ChangeEvent<HTMLInputElement>) => void;
}
}

export default function ListViewAdvanced() {
// This is used only for the example - renders the drawer inside the container
const containerRef = React.useRef<HTMLDivElement>(null);
Expand Down
16 changes: 9 additions & 7 deletions docs/data/data-grid/state/RestoreStateInitialState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Stack from '@mui/material/Stack';
import {
DataGridPro,
GridInitialState,
GridSlots,
GridSlotProps,
GridToolbarContainer,
GridToolbarDensitySelector,
GridToolbarFilterButton,
Expand All @@ -14,11 +14,13 @@ import {
} from '@mui/x-data-grid-pro';
import { useDemoData } from '@mui/x-data-grid-generator';

function GridCustomToolbar({
syncState,
}: {
syncState: (stateToSave: GridInitialState) => void;
}) {
declare module '@mui/x-data-grid' {
Copy link
Member Author

@LukasTy LukasTy Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If pro and premium package module augmentation are mixed in a single project—it goes haywire. 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some of this dogfooding—this is my main gripe with module augmentation. 🙈
If users extend the same types for different package versions—they come to experience unexpected behavior. 🤷

interface ToolbarPropsOverrides {
syncState: (stateToSave: GridInitialState) => void;
}
}

function GridCustomToolbar({ syncState }: GridSlotProps['toolbar']) {
const rootProps = useGridRootProps();
const apiRef = useGridApiContext();

Expand Down Expand Up @@ -63,7 +65,7 @@ export default function RestoreStateInitialState() {
<DataGridPro
{...data}
loading={loading}
slots={{ toolbar: GridCustomToolbar as GridSlots['toolbar'] }}
slots={{ toolbar: GridCustomToolbar }}
slotProps={{ toolbar: { syncState } }}
/>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<DataGridPro
{...data}
loading={loading}
slots={{ toolbar: GridCustomToolbar as GridSlots['toolbar'] }}
slots={{ toolbar: GridCustomToolbar }}
slotProps={{ toolbar: { syncState } }}
/>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"@types/moment-hijri": "^2.1.4",
"@types/moment-jalaali": "^0.7.9",
"@types/prop-types": "^15.7.13",
"@types/react-dom": "^18.3.0",
"@types/react-dom": "^18.3.1",
"@types/react-router-dom": "^5.3.3",
"@types/stylis": "^4.2.6",
"@types/webpack-bundle-analyzer": "^4.7.0",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@
"@types/lodash": "^4.17.12",
"@types/mocha": "^10.0.9",
"@types/node": "^20.17.3",
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react-test-renderer": "^18.3.0",
"@types/requestidlecallback": "^0.3.7",
"@types/sinon": "^17.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
GridRenderEditCellParams,
GridValueSetter,
GridPreProcessEditCellProps,
GridCellProps,
GridCellModes,
GridColDef,
} from '@mui/x-data-grid-pro';
import { getBasicGridData } from '@mui/x-data-grid-generator';
import { createRenderer, fireEvent, act, waitFor } from '@mui/internal-test-utils';
Expand Down Expand Up @@ -369,7 +369,7 @@ describe('<DataGridPro /> - Cell editing', () => {
});

describe('stopCellEditMode', () => {
function CustomEditComponent({ hasFocus }: GridCellProps) {
function CustomEditComponent({ hasFocus }: GridRenderEditCellParams) {
const ref = React.useRef<HTMLInputElement>(null);
React.useLayoutEffect(() => {
if (hasFocus) {
Expand Down Expand Up @@ -631,7 +631,9 @@ describe('<DataGridPro /> - Cell editing', () => {
});

it('should move focus to the cell below when cellToFocusAfter=below', async () => {
const renderEditCellProp = (props: GridCellProps) => <CustomEditComponent {...props} />;
const renderEditCellProp: GridColDef['renderEditCell'] = (props) => (
<CustomEditComponent {...props} />
);
render(<TestCase columnProps={{ renderEditCell: renderEditCellProp }} />);

act(() => apiRef.current.startCellEditMode({ id: 0, field: 'currencyPair' }));
Expand All @@ -647,7 +649,9 @@ describe('<DataGridPro /> - Cell editing', () => {
});

it('should move focus to the cell on the right when cellToFocusAfter=right', async () => {
const renderEditCellProp = (props: GridCellProps) => <CustomEditComponent {...props} />;
const renderEditCellProp: GridColDef['renderEditCell'] = (props) => (
<CustomEditComponent {...props} />
);
render(
<TestCase
{...getBasicGridData(1, 3)}
Expand All @@ -673,7 +677,9 @@ describe('<DataGridPro /> - Cell editing', () => {
});

it('should move focus to the cell on the left when cellToFocusAfter=left', async () => {
const renderEditCellProp = (props: GridCellProps) => <CustomEditComponent {...props} />;
const renderEditCellProp: GridColDef['renderEditCell'] = (props) => (
<CustomEditComponent {...props} />
);
render(
<TestCase
{...getBasicGridData(1, 3)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('<DataGridPro/> - Components', () => {
it(`should still publish the '${event}' event when overriding the '${prop}' prop in slots.cell`, () => {
const propHandler = spy();
const eventHandler = spy();
render(<TestCase slotProps={{ cell: { [prop]: propHandler } }} />);
render(<TestCase slotProps={{ cell: { [prop as any]: propHandler } }} />);
apiRef!.current.subscribeEvent(event, eventHandler);

expect(propHandler.callCount).to.equal(0);
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('<DataGridPro/> - Components', () => {
it(`should still publish the '${event}' event when overriding the '${prop}' prop in slots.row`, () => {
const propHandler = spy();
const eventHandler = spy();
render(<TestCase slotProps={{ row: { [prop]: propHandler } }} />);
render(<TestCase slotProps={{ row: { [prop as any]: propHandler } }} />);
apiRef!.current.subscribeEvent(event, eventHandler);

expect(propHandler.callCount).to.equal(0);
Expand Down
3 changes: 1 addition & 2 deletions packages/x-data-grid/src/components/GridRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface GridRowProps extends React.HTMLAttributes<HTMLDivElement> {
onDoubleClick?: React.MouseEventHandler<HTMLDivElement>;
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
[x: string]: any; // Allow custom attributes like data-* and aria-*
[x: `data-${string}`]: string;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mui/xgrid Are you sure we need to do this?
What problem is it solving? 🤔
No other X package is doing it, and neither Core is doing it. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context—no other package is providing this explicit type, if anyone needs to provide it, they are probably fighting TS as well.
Such props work on HTML and JSX elements as any prop with a - is ignored by TS.
Given that in our case these props are passed through slotProps, this causes slightly more problems, because they will show an error. 🤔

}

function EmptyCell({ width }: { width: number }) {
Expand Down Expand Up @@ -109,7 +109,6 @@ const GridRow = React.forwardRef<HTMLDivElement, GridRowProps>(function GridRow(
isLastVisible,
isNotVisible,
showBottomBorder,
focusedCell,
tabbableCell,
onClick,
onDoubleClick,
Expand Down
Loading