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

Typing of custom component to render in GridActionsCellItem #4654

Closed
2 tasks done
rafael-zilberman opened this issue Apr 26, 2022 · 5 comments · Fixed by #10344
Closed
2 tasks done

Typing of custom component to render in GridActionsCellItem #4654

rafael-zilberman opened this issue Apr 26, 2022 · 5 comments · Fixed by #10344
Labels
component: data grid This is the name of the generic UI component, not the React module! typescript

Comments

@rafael-zilberman
Copy link

rafael-zilberman commented Apr 26, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Why using version 5.6.1 of mui-x/data-grid we were using the component prop of the underlying ButtonBase component in order to integrate with react-router as follows:

<GridActionsCellItem
                        component={RouterLink}
                        to={`/notes`}
                        icon={<NoteIcon/>}
                        label="Notes"
                    />,

While Updating to versions older then 5.7.0 we are experiencing typing error stating that GridActionsCellItem doesn't have this prop enymore.

I followed the history of this component here but it seems that nothin relevant has been changed.

I found this commit containing bundling changes and did manged to find out that the difference between the latest version and the last version that has this feature working is type called GridActionsCellItem that has been added to the typing file in addition to GridActionsCellItemProps.

@rafael-zilberman rafael-zilberman added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 26, 2022
@Janpot
Copy link
Member

Janpot commented Apr 29, 2022

Was hitting the same issue after upgrading mui packages in Toolpad. Did a quick code review and I believe this issue has the same root cause as mui/material-ui#32392.

@m4theushw
Copy link
Member

@Janpot is right. The xxxProps interfaces of IconButton and MenuItem don't include component. This prop is only available when using the component itself, not when extending it (what we do). The following diff should be sufficient for now:

diff --git a/packages/grid/x-data-grid/src/components/cell/GridActionsCellItem.tsx b/packages/grid/x-data-grid/src/components/cell/GridActionsCellItem.tsx
index a54b786da..1e6096c64 100644
--- a/packages/grid/x-data-grid/src/components/cell/GridActionsCellItem.tsx
+++ b/packages/grid/x-data-grid/src/components/cell/GridActionsCellItem.tsx
@@ -7,6 +7,7 @@ import ListItemIcon from '@mui/material/ListItemIcon';
 export type GridActionsCellItemProps = {
   label: string;
   icon?: React.ReactElement;
+  component?: React.ElementType;
 } & (
   | ({ showInMenu?: false; icon: React.ReactElement } & IconButtonProps)
   | ({ showInMenu: true } & MenuItemProps)

@m4theushw m4theushw added component: data grid This is the name of the generic UI component, not the React module! typescript and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 6, 2022
@dfliess
Copy link

dfliess commented Sep 2, 2022

hi! has this been added ?

@rafael-zilberman
Copy link
Author

GridActionsCellItem

Still not fixed.

A nasty workaround for now:

import {GridActionsCellItem, GridActionsCellItemProps} from "@mui/x-data-grid";
import React, {RefAttributes} from "react";
import {Link as RouterLink} from "react-router-dom";

type GridLinkActionProps = {to: string} & GridActionsCellItemProps & RefAttributes<HTMLButtonElement>;

const GridLinkAction = ({to, ...props}: GridLinkActionProps) => {
    return (<RouterLink to={to}>
        <GridActionsCellItem {...props} />
    </RouterLink>);
};

export default GridLinkAction;

@boonya
Copy link

boonya commented Sep 14, 2023

Or, one more workaround

// This is a workaround due to known issue https://github.com/mui/mui-x/issues/4654
const EditLink = forwardRef<HTMLAnchorElement>((props, ref) => {
  return <RouterLink ref={ref} {...props} to={generatePath(ROUTES.edit, {id})} />;
});
EditLink.displayName = 'EditLink';

return (
  <GridActionsCellItem
    {...props}
    component={EditLink}
  />
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants