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] Text inside the cell is not truncated #3587

Closed
igor-serzhan opened this issue Jan 10, 2022 · 5 comments · Fixed by #3955
Closed

[data grid] Text inside the cell is not truncated #3587

igor-serzhan opened this issue Jan 10, 2022 · 5 comments · Fixed by #3955
Assignees
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! regression A bug, but worse

Comments

@igor-serzhan
Copy link

igor-serzhan commented Jan 10, 2022

Current behavior 😯

Text is not truncated with the ellipsis inside Data Grid Cell. As I see that happened after updating block model for the Cell (it was switched from display: block to display: flex in the latest v5.2.2 release.

Screenshot 2022-01-10 at 12 39 36

Expected behavior 🤔

Text should be truncated with the ellipsis like it was in the previous releases

Screenshot 2022-01-10 at 12 44 07

Steps to reproduce 🕹

Steps:

  1. Open https://codesandbox.io/s/datagrid-v5-2-2-truncated-text-7mc4p?file=/src/App.tsx
  2. See that the text is not truncated at the first row

Context 🔦

No response

Your environment 🌎

see code sandbox

Order ID 💳 (optional)

35653

@igor-serzhan igor-serzhan added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 10, 2022
@m4theushw
Copy link
Member

m4theushw commented Jan 10, 2022

The regression is coming from #3446. This PR changed from display: block to display: flex. You can restore the old truncation by proving a custom cell renderer as below:

const columns: GridColDef[] = [
  {
    field: "col2",
    headerName: "Column 2",
    width: 150,
    renderCell: ({ value }) => (
      <span style={{ overflow: "hidden", textOverflow: "ellipsis" }}>
        {value}
      </span>
    )
  },
];

Here's the updated CodeSandbox: https://codesandbox.io/s/datagrid-v5-2-2-truncated-text-forked-90bsv?file=/src/App.tsx

@m4theushw m4theushw added component: data grid This is the name of the generic UI component, not the React module! regression A bug, but worse and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 10, 2022
@igor-serzhan
Copy link
Author

@m4theushw yep, this will restore the old behavior, but it will require updating all simple cells in project.

@m4theushw
Copy link
Member

With a custom cell, you can restore completely the old behavior. It works for every cell.

const CustomCell = ({ height, width, ...other }: GridCellProps) => {
  const style = {
    minWidth: width,
    maxWidth: width,
    minHeight: height,
    maxHeight: height,
    lineHeight: `${height}px`,
  };

  return <GridCell {...other} height={height} width={width} style={style} />;
};

export default function App() {
  return (
    <div style={{ height: 300, width: '100%' }}>
      <DataGrid
        rows={rows}
        columns={columns}
        components={{ Cell: CustomCell }}
        sx={{
          '& .MuiDataGrid-cell': {
            display: 'block',
          },
        }}
      />
    </div>
  );
}

@igor-serzhan

This comment was marked as outdated.

@oliviertassinari oliviertassinari added the bug 🐛 Something doesn't work label Jan 30, 2022
@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 30, 2022

I'm reopening it. It's still a regression to fix. For #2859, I would argue that text ellipse is more important than having text wrapping by default.

Note that we cover this edge case in: https://mui.com/components/menus/#limitations.

As we fix this, I think that we should add two regression tests, one to cover #3446 and another one to cover #2859.

@DanailH DanailH self-assigned this Feb 7, 2022
@oliviertassinari oliviertassinari changed the title [DataGrid] Text inside the cell is not truncated [data grid] Text inside the cell is not truncated Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! regression A bug, but worse
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants