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

[data grid] renderCell position offset in case of display:flex #12543

Closed
PunkFleet opened this issue Mar 24, 2024 · 9 comments
Closed

[data grid] renderCell position offset in case of display:flex #12543

PunkFleet opened this issue Mar 24, 2024 · 9 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: extend Logic customizability

Comments

@PunkFleet
Copy link

PunkFleet commented Mar 24, 2024

Steps to reproduce

Link to live example: (required)
Whether it's a <Box> or a <Stack>, as long as it's a component in the flex state, it will reach the top of the cell when it's custom rendered.

 { field: 'category', headerName: 'Categories', width: 480, editable: true,            
            renderCell: (params) => {
                return (
                    <Box display="flex">
                        {params.value.map((item:any)=> (
                        <Chip key={item.id} label={item.name} />
                    ))}                    
                </Box>
                )
            },
        },

Steps:
1.
2.
3.

Current behavior

No response

Expected behavior

No response

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: rendercell

@PunkFleet PunkFleet added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 24, 2024
@zannager zannager added the component: data grid This is the name of the generic UI component, not the React module! label Mar 25, 2024
@michelengelen
Copy link
Member

Please provide a minimal reproduction test case with the latest version. This would help a lot 👷.

A live example would be perfect. You can find a examples and guides on how to find templates in our docs with which you can provide examples for your specific use-case: Support - Bug reproduction.

Thank you! 🙇🏼

@michelengelen michelengelen added status: waiting for author Issue with insufficient information customization: extend Logic customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 26, 2024
@michelengelen michelengelen changed the title renderCell position offset in case of display:flex [data grid] renderCell position offset in case of display:flex Mar 26, 2024
@PunkFleet
Copy link
Author

PunkFleet commented Mar 26, 2024

Please provide a minimal reproduction test case with the latest version. This would help a lot 👷.

A live example would be perfect. You can find a examples and guides on how to find templates in our docs with which you can provide examples for your specific use-case: Support - Bug reproduction.

Thank you! 🙇🏼

https://stackblitz.com/edit/react-x1ksay?file=Demo.tsx
I'm using this for now to achieve the same effect

<>
  {params.value.map((item:any)=> (
     <Chip sx={{mx:0.5}} key={item.id} label={item.name} />
  ))}                    
</>

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Mar 26, 2024
@michelengelen
Copy link
Member

You need to change the props on the rendered Stack for this to work. It did not take up the full cell height and did not align the items:

<Stack direction="row" spacing={1} alignItems={'center'} height={'100%'}>
  {params.value.map((item: any, index: number) => (
    <Chip key={index} label={item.name} />
  ))}
</Stack>

This will fix it!

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 27, 2024
@PunkFleet
Copy link
Author

You need to change the props on the rendered Stack for this to work. It did not take up the full cell height and did not align the items:

<Stack direction="row" spacing={1} alignItems={'center'} height={'100%'}>
  {params.value.map((item: any, index: number) => (
    <Chip key={index} label={item.name} />
  ))}
</Stack>

This will fix it!

Thank you, it works fine. But what I mean is that for the method of renderCell, and every time you need to position the parent element first to be able to render to the correct position, which is inconsistent with v6, and will bring visual differences when migration exists.

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Mar 27, 2024
@michelengelen
Copy link
Member

Yes, I do agree that this might happen.
I will tag this as a regression and add it to the board.
Thanks for raising this! 🙇🏼

@michelengelen michelengelen added regression A bug, but worse and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 27, 2024
@michelengelen
Copy link
Member

related issue #12642

@cherniavskii
Copy link
Member

As per our migration guide:

The cell element isn't display: flex by default. You can add display: 'flex' on the column definition to restore the behavior. This also means cells aren't vertically centered by default anymore, so if you have dynamic row height, you might want to set the display: 'flex' for all non-dynamic columns.
Source: https://mui.com/x/migration/migration-data-grid-v6/#css-classes-and-styling

This should fix it:

{
  field: 'category',
  headerName: 'Category',
  width: 400,
+ display: 'flex',
  renderCell: (params) => {

Working demo: https://stackblitz.com/edit/react-x1ksay-ppjmgk?file=Demo.tsx

@cherniavskii cherniavskii added status: waiting for author Issue with insufficient information and removed regression A bug, but worse labels Apr 9, 2024
@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Apr 10, 2024
Copy link

⚠️ This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@Birddle: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

@michelengelen
Copy link
Member

Thanks for pointing out the migration guiden @cherniavskii ... I must have overlooked this. :/

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! customization: extend Logic customizability
Projects
None yet
Development

No branches or pull requests

4 participants