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] Add sort icon for when column is unsorted #1415

Merged
merged 9 commits into from May 13, 2021

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented Apr 14, 2021

Closes #1076
Preview: https://deploy-preview-1415--material-ui-x.netlify.app/components/data-grid/demo

This PR changes the usage of the hideSortIcons prop. Using false will display an intermediary icon when no sort is applied. To keep the old behavior I've added another unsorted (default now) value to only show the sort icon when there's a sort applied.

@dtassone
Copy link
Member

Why do we need the 'unsorted' value exactly?

So does hideSortIcons allow to hide the sort icon for a specific column?

@m4theushw
Copy link
Member Author

m4theushw commented Apr 14, 2021

Why do we need the 'unsorted' value exactly?

unsorted is to not show the intermediary icon when the column is unsorted. It reproduces the current behavior. Here the age column uses it and the name column is false

So does hideSortIcons allow to hide the sort icon for a specific column?

Yep.

@dtassone
Copy link
Member

dtassone commented Apr 16, 2021

hideSortIcons I think this unsorted setting value is really confusing (to me at least).

To summarise:

  • users can set 3 icons, one for each direction and one when the column is unsorted.
  • users might want to hide the sort icons for all columns. For this, he can override the icons and put an empty component, or apply hideSortIcons to every sortable columns.
  • users might want to hide the sort icons for a specific column. Quite specific edge case IMO, but it could do it using hideSortIcons
  • users might want to hide the unsorted icon for a all columns, in that case, it can just put an empty component in the unsorted icon.
  • users might want to hide the unsorted icon for a specific column but show it for another one. hideSortIcons='unsorted'. TBH I don't that edge case is necessary. I believe that if users want to hide the unsorted icon, they would do it for all columns, it doesn't make sense to do it for one column and not another. It would be misleading. IMHO, I think we should remove the unsorted option for the reason above. Also the prop name is not ideal as it seems like a bool value, but it can take unsorted.

@m4theushw
Copy link
Member Author

m4theushw commented Apr 16, 2021

users might want to hide the sort icons for all columns. For this, he can override the icons and put an empty component, or apply hideSortIcons to every sortable columns.

If he changes the icon to null/false/undefined the default icon is used. If changed to an empty component (e.g. div) the button is rendered without the icon, but still takes space.

users might want to hide the unsorted icon for a all columns, in that case, it can just put an empty component in the unsorted icon.

Same problem as above.

users might want to hide the unsorted icon for a specific column but show it for another one. hideSortIcons='unsorted'. TBH I don't that edge case is necessary. I believe that if users want to hide the unsorted icon, they would do it for all columns, it doesn't make sense to do it for one column and not another. It would be misleading. IMHO, I think we should remove the unsorted option for the reason above. Also the prop name is not ideal as it seems like a bool value, but it can take unsorted.

The idea of controlling if the unsorted icon should be displayed came from this comment. However, instead of changing to an enum and creating a breaking change, I kept the boolean but added the third option. The Autocomplete API uses this approach in blurOnSelect and forcePopupIcon.

@dtassone
Copy link
Member

  • Remove unsorted value
  • Sortable columns should be identifiable with the unsorted icon
  • Icon components should allow null value.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 19, 2021

To add a bit to what we have discussed:

  • The root pain that [DataGrid] Allow sortable indicator on column headers without a sort applied #1076 covers is the accessibility affordance. How can it be made obvious that a column is sortable and another is not?
  • A new slot for the components prop can solve this issue, it would be rendered for the "unsorted" state on columns that are sortable.
  • Is there really a use case for hiding the sort icons? Why not disable the sort on the column in the first place? How about we remove the hideSortIcons property?
  • Accepting null for a component slot as a way to disable it could be an exception, we have never done this before, we shouldn't generalize it.

@dtassone
Copy link
Member

  • Issue on this one
    image
  • Sort icon should be displayed on the right for boolean
    image
  • Should we show the unsorted icon by default? If so, this icon does not mean unsorted but sorted desc. I would pick either importExport or unfoldMore from the MUI set. We could also apply an hover style which would increase the opacity to make it less intrusive.
  • We used to always show the menu icon on top of all icons, as it allows to do any actions, there is a small regression.
    now
    image
    image
    image
    before
    image
    image

as a side note, this column menu demo is really bad. It just shows how to disable it
https://deploy-preview-1415--material-ui-x.netlify.app/components/data-grid/columns/#column-menu

@m4theushw
Copy link
Member Author

Issue on this one

Fixed.

Sort icon should be displayed on the right for boolean

Fixed.

Should we show the unsorted icon by default? If so, this icon does not mean unsorted but sorted desc. I would pick either importExport or unfoldMore from the MUI set. We could also apply an hover style which would increase the opacity to make it less intrusive.

I changed to importExport but I'm still not happy. I think we should only show the icon on hover and use the same icon of the next sort direction. #1076 (comment)

We used to always show the menu icon on top of all icons, as it allows to do any actions, there is a small regression.

I related this problem here. It's a trade-off of fixing the alignment when using headerAlign=center. We can add a background but that's a visual breaking change.

@dtassone
Copy link
Member

dtassone commented Apr 23, 2021

I related this problem here. It's a trade-off of fixing the alignment when using headerAlign=center. We can add a background but that's a visual breaking change.

Yes but the tradeoff seems that it hurts more than the issue. Have you tried with a negative margin?

I changed to importExport but I'm still not happy. I think we should only show the icon on hover and use the same icon of the next sort direction. #1076 (comment)

Well the issue is to provide the ability to show the unsorted icon when the column is not sorted. If we show the next direction then it would be a different spec. It could be a new option on sortable columns. Something like showNextDirectionIconOnSortableColumns, but that would be a different feature. Demo candidate in doc? So we show the customizability of the feature or we wait for a user to create the issue.

For the current issue, we have 2 default options.

  1. we leave the unsorted icon null.
  2. we put an unsorted icon and apply a css to show it on hover.

As the grid should always come with as many feature as possible, I would lean towards 2.
For css I would go with a low opacity to show it in grey as it's just an info, compared to the active sort state in black.

@m4theushw
Copy link
Member Author

m4theushw commented Apr 23, 2021

Yes but the tradeoff seems that it hurts more than the issue. Have you tried with a negative margin?

Same problem. I applied a negative margin-right to the .MuiDataGrid-colCellTitleContainer class of the demo here. Since the column menu is transparent, everything below it is visible.

image

Well the issue is to provide the ability to show the unsorted icon when the column is not sorted. If we show the next direction then it would be a different spec. It could be a new option on sortable columns. Something like showNextDirectionIconOnSortableColumns, but that would be a different feature. Demo candidate in doc? So we show the customizability of the feature or we wait for a user to create the issue.

We added the icon slot for the unsorted icon, users can use any icon they want. My point is which icon should we use as the default one. Since we don't have a proper one my idea was to reproduce the same behavior of #1076 (comment) here. I just added now the GridColumnUnsortedIcon which is a "dynamic icon", showing the up arrow icon or the down arrow icon, depending on the sortingOrder. It can be used as the unsorted icon. I'll still have to fix the CSS to increase its alpha when the column is not sorted.

Animation

@oliviertassinari oliviertassinari added the component: data grid This is the name of the generic UI component, not the React module! label Apr 25, 2021
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.

docs/pages/api-docs/data-grid.md Outdated Show resolved Hide resolved
docs/pages/api-docs/x-grid.md Outdated Show resolved Hide resolved
@dtassone
Copy link
Member

As discussed

  1. let's restore the alignment issue
  2. fix the opacity

<ColumnHeaderFilterIcon counter={filterItemsCounter} />
{column.sortable && !column.hideSortIcons && (
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 had to invert the filter icon and the sort icon or it gonna have an empty space when the column is unsorted, but there's an active filter.

image

} else if (direction === 'desc') {
Icon = icons!.ColumnSortedDescendingIcon!;
}
return <Icon fontSize="small" className="MuiDataGrid-sortIcon" />;
Copy link
Member Author

Choose a reason for hiding this comment

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

Added fontSize to match with ColumnHeaderFilterIcon

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.

Outside of the font size regression?, it looks great.

@oliviertassinari oliviertassinari dismissed their stale review May 2, 2021 19:22

Opps, I have fired too quicky. There are visual regressions in the demos. For instance, here https://deploy-preview-1415--material-ui-x.netlify.app/components/data-grid/#mit-version, we need a larger width

@dtassone
Copy link
Member

dtassone commented May 3, 2021

There are also the issues with the icon on top of the other mentioned
#1415 (comment)

@oliviertassinari
Copy link
Member

oliviertassinari commented May 3, 2021

There are also the issues with the icon on top of the other mentioned #1415 (comment)

@dtassone I don't follow. What's the issue? Could you provide enough information on how to reproduce bugs when you report them?

@dtassone
Copy link
Member

dtassone commented May 3, 2021

There are also the issues with the icon on top of the other mentioned #1415 (comment)

@dtassone I don't follow. What's the issue? Could you provide enough information on how to reproduce bugs when you report them?

As mentioned in the link I put, if you reduce the size of the columns then the icons overlap each others

  • We used to always show the menu icon on top of all icons, as it allows to do any actions, there is a small regression.
    now
    image
    image
    image
    before
    image
    image

@m4theushw
Copy link
Member Author

As mentioned in the link I put, if you reduce the size of the columns then the icons overlap each others

@dtassone That's a side effect of removing overflow: hidden from .MuiDataGrid-colCellTitleContainer. It was removed because the value in the badge was being cut when reducing the size of the column. I can't think of a way to stack the column menu without adding the background.

With overflow: hidden:

Screenshot 2021-02-21 at 19 20 02

@oliviertassinari
Copy link
Member

oliviertassinari commented May 3, 2021

As mentioned in the link I put

The only link I can find is https://deploy-preview-1415--material-ui-x.netlify.app/components/data-grid/columns/#column-menu. I personally can't see any issue. The columns are not resizable on these demos.

I can see something wrong in https://deploy-preview-1415--material-ui-x.netlify.app/components/data-grid/columns/#column-reorder.

Screenshot 2021-05-03 at 13 29 57

@dtassone
Copy link
Member

dtassone commented May 3, 2021

try overriding the style below.

.MuiBadge-anchorOriginTopRightRectangle {
    top: 0;
    right: 0;
    transform: scale(1) translate(30%, -50%);  <= the fix is here, change from 50 to 30%.
    transform-origin: 100% 0%;
}

@m4theushw
Copy link
Member Author

try overriding the style below.

@dtassone Same problem.

image

If we invert the horizontal anchor of the Badge we can the solve the regression where the sort icon overlaps the column menu.

image

@dtassone
Copy link
Member

dtassone commented May 3, 2021

try overriding the style below.

@dtassone Same problem.

you have to restore the overflow and your changes

@oliviertassinari
Copy link
Member

oliviertassinari commented May 3, 2021

If we invert the horizontal anchor of the Badge we can the solve the regression where the sort icon overlaps the column menu.

@m4theushw It does feel better too. We would only need to make sure it works if the text alignment is reversed.

Otherwise, we could reduce the padding of .MuiDataGrid-colCell and add some of it on .MuiDataGrid-colCellTitleContainer, so that the overflow hidden doesn't hide the badge.

@oliviertassinari oliviertassinari added the new feature New feature or request label May 8, 2021
@DanailH
Copy link
Member

DanailH commented May 12, 2021

@m4theushw you would need to accept the new screenshots to fix the build 😉

@m4theushw m4theushw merged commit 2a3779c into mui:master May 13, 2021
@m4theushw m4theushw deleted the sort-icon branch May 13, 2021 17:46
@WilliamZimmermann
Copy link

Hello guys. Finally, the feature to "add sort icon for when column is unsorted" (for component) is not implemented? Because I can't see in the docs (for previous version [4] or the new version [5]) any references to it. If it is not implemented and will not be implemented soon, do you have any suggestion of workaround? Thx!

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! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] Allow sortable indicator on column headers without a sort applied
5 participants