Skip to content

[DataGrid] Focus the column header when clicking the sort icon - #23947

Merged
JCQuintas merged 2 commits into
mui:masterfrom
JCQuintas:fix/23940-sort-icon-focus
Oct 21, 2026
Merged

JCQuintas merged 2 commits into
mui:masterfrom
JCQuintas:fix/23940-sort-icon-focus

Conversation

@JCQuintas

Copy link
Copy Markdown
Member

Fixes #23940

Summary

Clicking a column header's sort icon moved focus to the icon button. After removing the sort with it and moving the pointer out of the header, the icon container became visibility: hidden, the browser dropped focus to document.body, and arrow-key navigation stopped working. Clicking the header title never had this problem because focus stays on the header cell.

GridColumnHeaderSortIcon now calls apiRef.current.setColumnHeaderFocus(field) on click, so focus lands on the header cell in both cases. hideColumnMenu uses the same call to restore focus when the column menu closes. It also keeps the grid's focus state in sync, which was previously cleared while the button held focus.

Clicking the sort icon focused the icon button. Once the sort was removed
and the pointer left the header, the button was hidden and focus fell back
to `document.body`, breaking keyboard navigation. Move focus to the column
header instead, matching a click on the header title.

Fixes mui#23940
@JCQuintas JCQuintas added type: bug It doesn't behave as expected. scope: data grid Changes related to the data grid. labels Oct 20, 2026
@JCQuintas JCQuintas self-assigned this Oct 20, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23947--material-ui-x.netlify.app/
QR code for https://deploy-preview-23947--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 🔺+114B(+0.03%) 🔺+15B(+0.01%)
@mui/x-data-grid-pro 🔺+114B(+0.02%) 🔺+19B(+0.01%)
@mui/x-data-grid-premium 🔺+114B(+0.02%) 🔺+21B(+0.01%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-scheduler 0B(0.00%) 0B(0.00%)
@mui/x-scheduler-premium 0B(0.00%) 0B(0.00%)
@mui/x-chat 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@JCQuintas
JCQuintas requested review from a team and noraleonte October 21, 2026 12:00
@JCQuintas
JCQuintas marked this pull request as ready for review October 21, 2026 12:00
@JCQuintas
JCQuintas merged commit 9cc0220 into mui:master Oct 21, 2026
22 checks passed
@JCQuintas
JCQuintas deleted the fix/23940-sort-icon-focus branch October 21, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: data grid Changes related to the data grid. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Mui Data Grid] Column header will lose focus when click on the sort icon to remove sort, but won't lose focus when click on header name to remove sort

2 participants