Repository navigation
[DataGrid] Describe column and action in sort button labels - #23755
Conversation
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
|
Updated the keyboard test to use the column-specific sort label. All three Data Grid browser suites pass locally (2,585 tests). |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
The type-label check is failing here and on #23756 because both PRs are missing a type label. Could a maintainer add |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
Merged the latest master and regenerated the localization report, keeping the new Turkish translations. Data Grid unit tests, the 106 Chromium sorting/keyboard tests, type checks and lint pass. |
LukasTy
left a comment
There was a problem hiding this comment.
Thank you for your contribution. 🙏
Combined Claude Opus and GPT Astra findings
The approach is correct and follows the columnMenuAriaLabel precedent. The column name and the next direction need fixes before merge.
- Wrong column name in the label (
GridColumnSortButton.tsx:83): the button gets the name fromapiRef.current.getColumn()during render. This gives a wrong name in two cases:- Grid header:
GridColumnHeaderSortIconisReact.memoand gets onlyfield/direction/sortingOrder, so aheaderNamechange does not re-render it. Repro: changeheaderNamefrom 'Brand' to 'Maker' withupdateColumns()or a newcolumnsprop. The title shows "Maker", but the button says "Sort Brand in ascending order". - Pivot panel: derived fields are only in
gridPivotInitialColumnsSelectorwhile pivoting is off, sogetColumn()returnsundefined. Repro: putdate-yearin the pivot columns with pivoting off. The panel shows "Shipped (Year)", but the button says "Sort date-year in ascending order". - Fix for both: let the caller pass the column name.
GridColumnHeaderItemhascolDef(asColumnHeaderMenuIcondoes), and the pivot panel has its initial columns. Add a test for theheaderNamechange.
- Grid header:
- Pivot panel label can contradict the action (
GridPivotPanelField.tsx:394): the button computes the next direction fromrootProps.sortingOrder, buthandleSort(line 307) always cycles asc -> desc -> none. Repro: withsortingOrder={['desc', 'asc']}, the unsorted "Sales region" field says "Sort Sales region in descending order", and a click setssort: 'asc'. Fix: makehandleSortusegetNextGridSortDirection(rootProps.sortingOrder, currentSort). - Localized grids now announce English (
localeTextConstants.ts:152): the 43 non-English locales translatecolumnHeaderSortIconLabel('Sortieren', 'Trier', ...), which was the aria-label. The new key is commented out in all of them, so these grids now announce "Sort Brand in ascending order" in English. Apps that overridecolumnHeaderSortIconLabelalso lose control of the aria-label (it now sets only the tooltip). This is the same trade-off as #16796. Please add translations where possible and state the behavior change in the PR body.
A few additional thoughts
- Is there a reason not to use the same label for the tooltip?
- If we reuse the same label, then we can deprecate
columnHeaderSortIconLabel, or ship this only in the next major and swap the labels.
What are your thoughts about this @mui/grid?
|
Fixed both name cases by passing the name from the caller, and aligned the pivot click with The tooltip still uses the existing key to keep that behavior compatible; I left deprecation to the API discussion. The 70 jsdom and 71 Chromium tests, all three Grid type checks, and lint pass. |
LukasTy
left a comment
There was a problem hiding this comment.
Thanks for the updates. All earlier findings are fixed.
- Header rename: the label updates after
updateColumns()and after a newcolumnsprop. - Pivot panel: with pivoting off, derived fields use the initial column name ("Shipped (Year)"). The click now follows
sortingOrder, and the label matches the result for['desc', 'asc']and['desc', 'asc', null]. - Localization: 11 locales now have translations, and the PR body states the behavior change.
Translations: all 11 are grammatical and describe the correct next action. Some changes are recommended:
jaJP: the tooltip and the menu use "ソート" ('ソート', '昇順ソート', 'ソート解除'), but the new label uses "並べ替え". Use the same term:${columnName}を昇順でソート,${columnName}を降順でソート,${columnName}のソートを解除.ptPT: the menu uses "Classificar" ('Classificar por ordem crescente'), but the new label uses "Ordenar". Use the same term (see the string below).frFR,itIT,esES,ptBR,ptPT: the column menu label in these locales says "the column X" ('Menu pour la colonne X', 'Menù della colonna X', 'Menú de la columna X', 'Menu da coluna X'). Use the same pattern here. It also fixes the French elision ("de Âge" must be "d'Âge") and the Italian "da X", which copies the English "from".frFR:Trier la colonne ${columnName} par ordre croissant/décroissant,Supprimer le tri de la colonne ${columnName}itIT:Ordina la colonna ${columnName} in ordine crescente/decrescente,Rimuovi l'ordinamento della colonna ${columnName}esES:Ordenar la columna ${columnName} de forma ascendente/descendente,Quitar la ordenación de la columna ${columnName}ptBR:Ordenar a coluna ${columnName} em ordem crescente/decrescente,Remover a ordenação da coluna ${columnName}ptPT:Classificar a coluna ${columnName} por ordem crescente/decrescente,Remover a classificação da coluna ${columnName}
Optional: columnName is now a required prop on the public GridColumnHeaderSortIconProps. Code that renders GridColumnHeaderSortIcon directly gets a type error, and without the prop the label reads "Sort undefined in ascending order". A GitHub code search finds no such usage outside forks, so the risk is low. You can make the prop optional with a field fallback to keep the type non-breaking.
I would still like to leave the approval right to the Grid team.
There is also the topic of reusing the same labels for the tooltip.
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
Aligned the six locales with the existing menu wording and made |
|
Netlify failed in |
LukasTy
left a comment
There was a problem hiding this comment.
Thank you for the contribution. 🙏
LGTM, but I would still like a 2nd look from the Data Grid team.
I'd suggest deprecating the existing "Sort" label and using the same label for the <Tooltip /> title, but maybe it's just me, and others think otherwise for some reason. 🤷♂️
Instead of deprecation, how about extending current columnHeaderSortIconLabel: string | (columnName: string, direction: GridSortDirection) => string; |
That's also a very nice option. 👍 |
Sorry, I missed that part. I'm leaning a bit more towards showing simple "Sort" or "Sort asc/Sort desc/Unsort" labels in the tooltip, but no strong preference here. |
|
I've kept the short tooltip separate from the column/action text in the accessible label. Please let me know if you'd prefer the union API. The Thai translation is in; sorting tests pass in jsdom and Chromium (38 each), along with all four Grid package type checks. |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
@minwookshin, could you merge master and resolve the conflicts? |
|
Merged master and regenerated the localization report. Sorting/pivot tests pass in jsdom (62) and Chromium (63), along with grid types, lint and builds. Argos reports one changed screenshot; could you review the comparison? |
Fixes #16456.
Give each column sort button a unique, localized accessible name. The name contains the column name and the action of the next click, for example "Sort Brand in ascending order", "Sort Brand in descending order", or "Remove sorting from Brand".
Changes
columnHeaderSortIconAriaLabel(columnName, direction)locale key.directionis the sort direction that the next click applies.columnNameprop toGridColumnHeaderSortIcon. The column header passesheaderName ?? field, so the label updates after a newcolumnsprop orupdateColumns(). A custom sort icon slot without this prop usesfield.sortingOrder, so the click and the label always agree.Behavior changes
columnHeaderSortIconLabelnow sets only the tooltip. Before this change, it also set the accessible name of the sort button. Apps with a custom translation ofcolumnHeaderSortIconLabelmust also translatecolumnHeaderSortIconAriaLabel. An explicitaria-labelinslotProps.columnHeaderSortIconstill overrides the accessible name.The pivot panel sort button now follows the
sortingOrderprop. Before this change, it always used ascending, descending, then no sort. With the defaultsortingOrder, the behavior does not change.I have followed (at least) the PR section of the contributing guide.