Skip to content

Conversation

lauri865
Copy link
Contributor

Fixes #19320.

Albeit the focused element jumping in and out of render context part probably is not ideal (also doesn't support keyboard), it fixes the biggest issue for now.

@mui-bot
Copy link

mui-bot commented Aug 25, 2025

Deploy preview: https://deploy-preview-19323--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid ▼-124B(-0.02%) 🔺+54B(+0.03%)
@mui/x-data-grid-pro ▼-124B(-0.02%) 🔺+13B(+0.01%)
@mui/x-data-grid-premium ▼-124B(-0.01%) 🔺+28B(+0.01%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 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%)

Details of bundle changes

Generated by 🚫 dangerJS against e230320

@romgrk romgrk added scope: data grid Changes related to the data grid. type: regression A bug, but worse, it used to behave as expected. labels Aug 25, 2025
Comment on lines 272 to 275
elementToFocus?.focus();
if (apiRef.current.columnHeadersContainerRef?.current) {
apiRef.current.columnHeadersContainerRef.current.scrollLeft = 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For the context, this was added here: #4280

Copy link
Contributor Author

@lauri865 lauri865 Aug 25, 2025

Choose a reason for hiding this comment

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

Whatever it fixed should be irrelevant since position: sticky? columnHeadersContainer is not scrollable anyways (anymore).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it should be irrelevant.

Comment on lines -87 to -99
React.useLayoutEffect(() => {
const columnMenuState = apiRef.current.state.columnMenu;
if (hasFocus && !columnMenuState.open) {
const focusableElement =
headerCellRef.current!.querySelector<HTMLElement>('[tabindex="0"]');
const elementToFocus = focusableElement || headerCellRef.current;
elementToFocus?.focus();
if (apiRef.current.columnHeadersContainerRef?.current) {
apiRef.current.columnHeadersContainerRef.current.scrollLeft = 0;
}
}
}, [apiRef, hasFocus]);

Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't used/useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seemed like a duplicated logic that was already present in the parent components.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, I've tested and the functionality seems to work even without this.

@lauri865
Copy link
Contributor Author

Need to add a fallback for Chrome on Android it seems, similar to GridCell:

https://caniuse.com/mdn-api_htmlelement_focus_options_preventscroll_parameter

@lauri865
Copy link
Contributor Author

Should be ready to merge now.

@romgrk romgrk merged commit e1ad902 into mui:master Aug 27, 2025
21 checks passed
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: regression A bug, but worse, it used to behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[data grid] Scroll jumps if column header is focused and columns flicker when scrolling

3 participants