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] Fix display of row count and selected rows on mobile #508

Merged
merged 11 commits into from
Nov 4, 2020

Conversation

DanailH
Copy link
Member

@DanailH DanailH commented Oct 29, 2020

Fixes #440

This PR aims to solve the issue of having the Total Rows and rows selected counts hidden on small screens. I didn't change the styling but only made the 2 files visible.

Screenshot 2020-10-29 at 15 22 44

@DanailH DanailH self-assigned this Oct 29, 2020
@oliviertassinari oliviertassinari changed the title Enable Row Count and Selected Rows on mobile [DataGrid] Fix display of row count and selected rows on mobile Oct 29, 2020
@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! labels Oct 29, 2020
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

@DanailH
Copy link
Member Author

DanailH commented Oct 29, 2020

It doesn't fit on mobile with pagination:

Capture d’écran 2020-10-29 à 15 40 08

https://deploy-preview-508--material-ui-x.netlify.app/components/data-grid/pagination/

Yes about that, I saw it (its event worst if you select a row) but I'm not sure how to handle it design-wise. Maybe we can have a discussion about it. The fix will be easy to implement. What do you think @oliviertassinari ?

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 29, 2020

What about we make it use two rows if the features are enabled? cc @dtassone

@DanailH
Copy link
Member Author

DanailH commented Oct 29, 2020

That would definitely solve the issue but with the tradeoff that the footer height will increase and if you have set your grid to height to a smaller number there may bot be enough height for the visible part (although I'm not sure how valid of an argument that is since setting the height of the Grid is done by the user)

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 29, 2020

Oh right, in this case, maybe we can have at most one footer "row":

  • pagination wins over selected row & row count.
  • If pagination={false} hideFooterRowCount hideFooterSelectedRowCount => hide the footer.

@dtassone
Copy link
Member

How about we hide a few things in the pagination component.
So we just display 2 buttons to navigate bw pages

@dtassone
Copy link
Member

For the info about rows we can change it as well, reduce the wordings or put it on 2 rows

200 Rows, 1 selected

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 29, 2020

For the info about rows we can change it as well, reduce the wordings or put it on 2 rows

The wordings will need to be translated with an API, it will increase it. It might also still overflow in another locale, so I would vote against for simplicity. Can a mobile user leverage the information?

@dtassone
Copy link
Member

For the info about rows we can change it as well, reduce the wordings or put it on 2 rows

The wordings will need to be translated with an API, it will increase it. It might also still overflow in another locale, so I would vote against for simplicity. Can a mobile user leverage the information?

Yeah maybe just the total rows on mobile. Also can we put only 2 btns for pagination?

@DanailH
Copy link
Member Author

DanailH commented Oct 29, 2020

I'll play around and create a couple of options and attach them here as screenshots to see which one will look the best

@oliviertassinari
Copy link
Member

Mayby hiding the rows per page would be enough. The best case is if we can manage the logic with CSS only, so its easier to customize (as opposed to changing the DOM).

@DanailH
Copy link
Member Author

DanailH commented Oct 30, 2020

Ok I did some tests and it seems that the easies and most secure option is what @oliviertassinari suggested - hide the selected row and total row count. The reason is that the for the footer we are using the TablePagination from core and changing that will be tricky. The other option is to implement our own DataGrid footer component. I'm open for suggestions :D

@oliviertassinari
Copy link
Member

@DanailH Sounds good, so and on desktop, we leave it untouched.

@dtassone
Copy link
Member

Ok I did some tests and it seems that the easies and most secure option is what @oliviertassinari suggested - hide the selected row and total row count. The reason is that the for the footer we are using the TablePagination from core and changing that will be tricky. The other option is to implement our own DataGrid footer component. I'm open for suggestions :D

How about we keep what is circled in orange only?

image

The row counter is actually displayed already in the pagination

@DanailH
Copy link
Member Author

DanailH commented Oct 30, 2020

@DanailH Sounds good, so and on desktop, we leave it untouched.

Sure, we can do that. Currently, it hides it also on desktop but I can easily change it 😉

@DanailH
Copy link
Member Author

DanailH commented Oct 30, 2020

Ok I did some tests and it seems that the easies and most secure option is what @oliviertassinari suggested - hide the selected row and total row count. The reason is that the for the footer we are using the TablePagination from core and changing that will be tricky. The other option is to implement our own DataGrid footer component. I'm open for suggestions :D

How about we keep what is circled in orange only?

image

The row counter is actually displayed already in the pagination

This change will still require to update/change the TablePagination component from core because the rows per page section is in it and there is no API to hide it or at least I cant' see one -> https://material-ui.com/api/table-pagination/

@dtassone
Copy link
Member

Ok I did some tests and it seems that the easies and most secure option is what @oliviertassinari suggested - hide the selected row and total row count. The reason is that the for the footer we are using the TablePagination from core and changing that will be tricky. The other option is to implement our own DataGrid footer component. I'm open for suggestions :D

How about we keep what is circled in orange only?
image
The row counter is actually displayed already in the pagination

This change will still require to update/change the TablePagination component from core because the rows per page section is in it and there is no API to hide it or at least I cant' see one -> https://material-ui.com/api/table-pagination/

You can do it with CSS

@dtassone
Copy link
Member

You can also display the grid row counter only when there is no pagination

@DanailH
Copy link
Member Author

DanailH commented Oct 30, 2020

Yes, that's what I'm doing now. If the pagination is available the Total rows and Rows selected are hidden.

@DanailH
Copy link
Member Author

DanailH commented Oct 30, 2020

Ok I did some tests and it seems that the easies and most secure option is what @oliviertassinari suggested - hide the selected row and total row count. The reason is that the for the footer we are using the TablePagination from core and changing that will be tricky. The other option is to implement our own DataGrid footer component. I'm open for suggestions :D

How about we keep what is circled in orange only?
image
The row counter is actually displayed already in the pagination

This change will still require to update/change the TablePagination component from core because the rows per page section is in it and there is no API to hide it or at least I cant' see one -> https://material-ui.com/api/table-pagination/

You can do it with CSS

True, but should we do it like this, hack our own components. It's better to introduce a prop in the TablePagination to hide then. I can do it, it's not a problem @oliviertassinari ?

@oliviertassinari
Copy link
Member

@DanailH The data grid relies on core v4 so far, we can't expect any changes to land in it. However, the table pagination exposes enough public API, so no need to hack around.

@@ -11,6 +12,16 @@ export interface PaginationComponentProps {
rowsPerPageOptions?: number[];
}

// Used to hide the drop down select from the TablePaginagion
const useStyles = makeStyles({
Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I've updated the logic with what we discussed during the planning today, here is the summary:

  • Remove Total Rows when the pagination is available
  • Remove the select and the label inside the TablePagination
  • Update the login so the selected rows is only shown on desktop when the pagination is available
  • Adjust the footer items alignment when there is only pagination (it should be aways on the right side)

Last but not least a question - these styles are needed to hide the select from the TablePagination component but I'm not sure it this is the best place to keep them, ideas ?

@DanailH
Copy link
Member Author

DanailH commented Nov 2, 2020

Hmm I guess the flaky test is this one Chrome 84.0.4147.89 (Mac OS 10.15.6) <XGrid /> keyboard cell navigation with arrows FAILED 😅

@oliviertassinari
Copy link
Member

@DanailH CircleCI allows to rerun test from fails. I have launch it.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

I wonder how to best test this. Maybe DOM and class name assertions would be ideal.

packages/grid/_modules_/grid/components/pagination.tsx Outdated Show resolved Hide resolved
ref={ref}
className={classnames({
'MuiDataGrid-footer-pagination-visible': isPaginationAvailable,
'MuiDataGrid-footer-justifyContent-right': justifyItemsRight,
Copy link
Member

Choose a reason for hiding this comment

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

Adding a hypen for separating internal components was one thing, doing it for naming is another.

Suggested change
'MuiDataGrid-footer-justifyContent-right': justifyItemsRight,
'MuiDataGrid-footer-justifyContentRight': justifyItemsRight,

Copy link
Member

Choose a reason for hiding this comment

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

Instead of "right" using "end" would be better for RTL.

Copy link
Member

Choose a reason for hiding this comment

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

What if we render an empty div instead so we don't have to apply a custom class name?

Copy link
Member

Choose a reason for hiding this comment

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

Or we could also inverse the direction of the flex container. That could be even better if that's what most people would want, not sure.

Copy link
Member Author

@DanailH DanailH Nov 3, 2020

Choose a reason for hiding this comment

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

I was thinking of rendering an empty div as well but I didn't like how it looked. Maybe we can reintroduce it. The benefit is that if we add a single empty div around the row selected we don't need to add any additional CSS logic/styles.

'& .MuiDataGrid-rowCount, & .MuiDataGrid-selectedRowCount': {
visibility: 'hidden',
[theme.breakpoints.up('md')]: {
visibility: 'visible',
Copy link
Member

Choose a reason for hiding this comment

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

Why not using display none?

Copy link
Member Author

Choose a reason for hiding this comment

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

I need it to take space. The reason is that we want the pagination to always be right-aligned. If I make it display: none then the logic to aways align the pagination on the right will be unnecessarily complex.

packages/grid/_modules_/grid/components/default-footer.tsx Outdated Show resolved Hide resolved
DanailH and others added 3 commits November 3, 2020 09:54
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
…ailH/material-ui-x into fix/DataGrid-440-footer-issue-mobile
@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 3, 2020

I wonder if we shouldn't use the breakpoint before md (960px) but sm (600px). People can customize it but that still seems to be common enough per mui/material-ui#21902. It's also what we use in the main repo (sm).

@DanailH
Copy link
Member Author

DanailH commented Nov 3, 2020

I wonder if we shouldn't use the breakpoint before md (960px) but sm (600px). People can customize it but that still seems to be common enough per mui-org/material-ui#21902. It's also what we use in the main repo (sm).

I just went ahead and changed it to sm. This is the only place where we use a breakpoint and with the new changes (we hide part of the TablePagination) there is enough space to have both parts on a single line before hitting sm resolution

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

  • We can no longer change the number of rows per page on desktop, maybe use CSS to target the first .caption style on mobile?
  • Something is strange with this demo:

https://deploy-preview-508--material-ui-x.netlify.app/components/data-grid/pagination/#auto-size

Capture d’écran 2020-11-03 à 17 38 26

@DanailH
Copy link
Member Author

DanailH commented Nov 3, 2020

  • We can no longer change the number of rows per page on desktop, maybe use CSS to target the first .caption style on mobile?
  • Something is strange with this demo:

https://deploy-preview-508--material-ui-x.netlify.app/components/data-grid/pagination/#auto-size

Capture d’écran 2020-11-03 à 17 38 26

I'll check the demo. Regarding the other point - as far as I understood that was the desired behaviour from our discussion, to hide both the label and the select? I can only hide the label and keep the select.

@oliviertassinari
Copy link
Member

I'll check the demo. Regarding the other point - as far as I understood that was the desired behaviour from our discussion, to hide both the label and the select? I can only hide the label and keep the select.

I was under the assumption that it was only on mobile to save space. From my perspective, if we were to change this on desktop too, it would be the type of change that should be done at the TablePagination level, not in the data grid.

@DanailH
Copy link
Member Author

DanailH commented Nov 4, 2020

I'll check the demo. Regarding the other point - as far as I understood that was the desired behaviour from our discussion, to hide both the label and the select? I can only hide the label and keep the select.

I was under the assumption that it was only on mobile to save space. From my perspective, if we were to change this on desktop too, it would be the type of change that should be done at the TablePagination level, not in the data grid.

Ok, hopefully, the last update - I've only hidden the Rows per page + the select from mobile resolutions, they are now visible on desktop.

The drawback - I had to return the media query to md because if you have a row selected and the pagination on small but not telephone screen resolution the rows selected falls on 2 lines and a scroll may appear.

@DanailH DanailH merged commit 1071158 into mui:master Nov 4, 2020
dtassone pushed a commit to dtassone/material-ui-x that referenced this pull request Nov 9, 2020
)

* Enable Row Count and Selected Rows on mobile

* Hide RowCount and SelectedRowCount if paginationComponent is provided

* Hide Row count and Selected rows on mobile if Pagination is available

* Hide Total rows when there is pagination, remove select and label from TablePagination

* Update packages/grid/_modules_/grid/components/pagination.tsx

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* Adjust class names

* Swap Total Row and rows selected places

* Update footer breakpoint to "sm"

* Fix formatting

* Fix responsive styles

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] Footer issue on mobile
3 participants