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

[data grid] Get correct width for invisible iconContainer #16399

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ function extractColumnWidths(
: excludeOutliers(widths, options.outliersFactor);

if (options.includeHeaders) {
const sortModel = apiRef.current.getSortModel();
const header = findGridHeader(apiRef.current, column.field);
if (header) {
const sortItem = sortModel.find((item) => item.field === column.field);
const isColumnSorted = sortItem != null && sortItem.sort != null;
const title = header.querySelector(`.${gridClasses.columnHeaderTitle}`);
const content = header.querySelector(`.${gridClasses.columnHeaderTitleContainerContent}`)!;
const iconContainer = header.querySelector(`.${gridClasses.iconButtonContainer}`);
Expand All @@ -220,7 +223,9 @@ function extractColumnWidths(
const width =
contentWidth +
paddingWidth +
(iconContainer?.clientWidth ?? 0) +
// clientWidth is `0`, since the element is hidden and we query it from a ref
// we need to use scrollWidth instead in this case.
(iconContainer?.[isColumnSorted ? 'scrollWidth' : 'clientWidth'] ?? 0) +
(menuContainer?.clientWidth ?? 0);

filteredWidths.push(width);
Expand Down