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

[DataGrid] Allow for truncated and multiline content in grid cells #3955

Merged
merged 4 commits into from
Feb 24, 2022

Conversation

DanailH
Copy link
Member

@DanailH DanailH commented Feb 15, 2022

Fixes #3587

I added 2 snaps to make sure that we don't break it again.
To fix this I had to wrap the content of the cell in a div element. If a renderCell is provided its return value won't be wrapped in that div element.

Storybook: https://deploy-preview-3955--material-ui-x.netlify.app/storybook/?path=/story/datagridpro-test-styling--truncated-cell-text-snap

@DanailH DanailH added 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 labels Feb 15, 2022
@DanailH DanailH self-assigned this Feb 15, 2022
@mui-bot
Copy link

mui-bot commented Feb 15, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 322.8 604 343.6 399.5 105.325
Sort 100k rows ms 609.6 922 891.8 826.4 118.463
Select 100k rows ms 207.7 499.9 224.7 290.2 109.609
Deselect 100k rows ms 118.6 214.9 172.2 170.22 30.741

Generated by 🚫 dangerJS against 0f5bffc

@cherniavskii
Copy link
Member

What if we introduce GridColDef.noWrap that defaults to true?
Then we can do something like this:

const content = children != null ? children : valueToRender?.toString();
// ...

{noWrap ? <div className={classes.content}>{content}</div> : content}

This will allow to control whether the content is wrapped or not, regardless renderCell presence.
It should be backwards-compatible as well.
Does it make sense?

@DanailH
Copy link
Member Author

DanailH commented Feb 15, 2022

@cherniavskii I was thinking of adding another option to the GridColDef to distinguish the 2 but without it looks cleaner. Also with it, additional configuration will probably be needed for the bug to be actually fixed. With the current solution, there are no regressions and both cases (truncated and multiline) will work.

@cherniavskii
Copy link
Member

Also with it, additional configuration will probably be needed for the bug to be actually fixed

If you mean #3587, then it will be fixed by default with no configuration.

With the current solution, there are no regressions

What about the one you mentioned in PR description?

It can only impact the case where a renderCell is provided with long text content. In that case, the text won't overflow but break and fit into the cell

@cherniavskii
Copy link
Member

Adding noWrap option has one advantage - no need to use renderCell to enable text wrapping

@DanailH
Copy link
Member Author

DanailH commented Feb 15, 2022

What about the one you mentioned in PR description?

It can only impact the case where a renderCell is provided with long text content. In that case, the text won't overflow but break and fit into the cell

that is already fixed by keeping the whiteSpace: 'nowrap'

@m4theushw
Copy link
Member

@cherniavskii Whether we add noWrap or not, it could be a prop in GridCell. This avoids adding more options to GridColDef that are only used in a small part of the grid.

@cherniavskii
Copy link
Member

cherniavskii commented Feb 15, 2022

that is already fixed by keeping the whiteSpace: 'nowrap'

Ok, I didn't notice that change. It's great then!

@m4theushw

Whether we add noWrap or not, it could be a prop in GridCell

I like this!
This can be done separately thought, since this PR is 100% backwards compatible now :)

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 17, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 23, 2022
Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

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

Looks good.

@DanailH DanailH merged commit 977f77b into mui:master Feb 24, 2022
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 this pull request may close these issues.

[data grid] Text inside the cell is not truncated
4 participants