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

fix: flush frozen columns before calculating auto width #8516

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all 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
5 changes: 5 additions & 0 deletions packages/grid/src/vaadin-grid-mixin.js
Original file line number Diff line number Diff line change
@@ -417,6 +417,11 @@ export const GridMixin = (superClass) =>
this._debouncerHiddenChanged.flush();
}

// Flush frozen column updates
if (this.__debounceUpdateFrozenColumn) {
this.__debounceUpdateFrozenColumn.flush();
}

this.__intrinsicWidthCache = new Map();
// Cache the viewport rows to avoid unnecessary reflows while measuring the column widths
const fvi = this._firstVisibleIndex;
30 changes: 29 additions & 1 deletion packages/grid/test/column-auto-width.common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { expect } from '@vaadin/chai-plugins';
import { aTimeout, fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import { flushGrid, getContainerCell } from './helpers.js';
import { flushGrid, getContainerCell, getHeaderCell } from './helpers.js';

function getCellIntrinsicWidth(cell) {
const originalInlineStyles = cell.getAttribute('style');
// Prepare the cell for having its intrinsic width measured
cell.style.width = 'auto';
cell.style.position = 'absolute';

const intrinsicWidth = parseFloat(getComputedStyle(cell).width);

// Restore the original inline styles
cell.setAttribute('style', originalInlineStyles);
return intrinsicWidth;
}

describe('column auto-width', () => {
let grid;
@@ -252,6 +265,21 @@ describe('column auto-width', () => {
expectColumnWidthsToBeOk(columns);
});

it('should have correct column widths for frozen columns with no items', async () => {
const [firstColumn, lastColumn] = [columns[0], columns[columns.length - 1]];
firstColumn.frozen = true;
firstColumn.header = 'foo bar baz';
lastColumn.frozenToEnd = true;

grid.recalculateColumnWidths();
await recalculateWidths();

const frozenHeaderCell = getHeaderCell(grid, 0, 0);
const frozenToEndHeaderCell = getHeaderCell(grid, 0, columns.length - 1);
expect(parseFloat(firstColumn.width)).not.to.be.lessThan(getCellIntrinsicWidth(frozenHeaderCell));
expect(parseFloat(lastColumn.width)).not.to.be.lessThan(getCellIntrinsicWidth(frozenToEndHeaderCell));
});

describe('focusButtonMode column', () => {
beforeEach(async () => {
const column = document.createElement('vaadin-grid-column');
2 changes: 1 addition & 1 deletion packages/grid/test/frozen-columns.common.js
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ const frozenGridFixture = (frozen, frozenToEnd) => {
});

it('should update frozen columns once on init', () => {
expect(grid._updateFrozenColumn.callCount).to.equal(1);
expect(grid._updateFrozenColumn.callCount).to.be.lessThan(3);
});

['header', 'body'].forEach((container) => {