Skip to content

Commit

Permalink
fix: measure auto-width correctly for focusButtonMode columns (#7046)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwajtr authored Jan 4, 2024
1 parent 96a64eb commit b152955
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/grid/src/vaadin-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ export const GridMixin = (superClass) =>
cell.style.position = '';
}
});

if (autoWidth) {
this.$.scroller.setAttribute('measuring-auto-width', '');
} else {
this.$.scroller.removeAttribute('measuring-auto-width');
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/grid/src/vaadin-grid-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ export const gridStyles = css`
inset: 0;
}
/* Switch the focusButtonMode wrapping element to "position: static" temporarily
when measuring real width of the cells in the auto-width columns. */
[measuring-auto-width] [part~='cell'] > [tabindex] {
position: static;
}
[part~='details-cell'] {
position: absolute;
bottom: 0;
Expand Down
22 changes: 21 additions & 1 deletion packages/grid/test/column-auto-width.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import { aTimeout, fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import { flushGrid, getContainerCell } from './helpers.js';

Expand Down Expand Up @@ -221,6 +221,26 @@ describe('column auto-width', () => {

expect(headerCell.getBoundingClientRect().width).to.be.closeTo(headerCellWidth, 5);
});

describe('focusButtonMode column', () => {
beforeEach(async () => {
const column = document.createElement('vaadin-grid-column');
column.autoWidth = true;
column.path = 'b';
column._focusButtonMode = true;
grid.insertBefore(column, grid.firstElementChild);
columns = grid.querySelectorAll('vaadin-grid-column');

await aTimeout(0);
});

it('should calculate auto-width of focusButtonMode column correctly', async () => {
grid.items = testItems;

await recalculateWidths();
expectColumnWidthsToBeOk(columns, [114, 71, 114, 84, 107]);
});
});
});

describe('tree column', () => {
Expand Down

0 comments on commit b152955

Please sign in to comment.