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: measure auto-width correctly for focusButtonMode columns #7046

Merged
Show file tree
Hide file tree
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
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