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: make auto-width and text-align usable in custom slot #6602

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion packages/grid/src/vaadin-grid-column-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export const ColumnBaseMixin = (superClass) =>

/** @private */
_textAlignChanged(textAlign) {
if (textAlign === undefined) {
if (textAlign === undefined || this._grid === undefined) {
return;
}
if (['start', 'end', 'center'].indexOf(textAlign) === -1) {
Expand Down
5 changes: 4 additions & 1 deletion packages/grid/src/vaadin-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ export const GridMixin = (superClass) =>
return 0;
}

const columnWidth = Math.max(this.__getIntrinsicWidth(col), this.__getDistributedWidth(col.parentElement, col));
const columnWidth = Math.max(
this.__getIntrinsicWidth(col),
this.__getDistributedWidth((col.assignedSlot || col).parentElement, col),
);
tomivirkki marked this conversation as resolved.
Show resolved Hide resolved

// We're processing a regular grid-column and not a grid-column-group
if (!innerColumn) {
Expand Down
2 changes: 2 additions & 0 deletions packages/grid/test/grid-wrapper-polymer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '../all-imports.js';
import './grid-wrapper.common.js';
59 changes: 59 additions & 0 deletions packages/grid/test/grid-wrapper.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync, nextFrame } from '@vaadin/testing-helpers';
import { flushGrid, getBodyCellContent } from './helpers';
tomivirkki marked this conversation as resolved.
Show resolved Hide resolved

class GridWrapper extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' }).innerHTML = `
<vaadin-grid id="grid">
<vaadin-grid-column-group>
<slot name="group"></slot>
</vaadin-grid-column-group>
<slot></slot>
</vaadin-grid>
`;
}
}

customElements.define('grid-wrapper', GridWrapper);

async function initGrid(wrapper) {
const grid = wrapper.shadowRoot.querySelector('vaadin-grid');
grid.items = Array.from({ length: 10 }).map((_, i) => ({ name: `Person ${i}` }));
flushGrid(grid);
await nextFrame();
return grid;
}

describe('columns slotted in custom element', () => {
it('should render column correctly with auto-width defined', async () => {
const wrapper = fixtureSync(
'<grid-wrapper><vaadin-grid-column path="name" auto-width></vaadin-grid-column></grid-wrapper>',
);
const grid = await initGrid(wrapper);

expect(getBodyCellContent(grid, 0, 0).textContent).to.equal('Person 0');
});

it('should render column correctly with auto-width inside a column-group', async () => {
const wrapper = fixtureSync(
'<grid-wrapper><vaadin-grid-column slot="group" path="name" auto-width></vaadin-grid-column></grid-wrapper>',
);
const grid = await initGrid(wrapper);

expect(getBodyCellContent(grid, 0, 0).textContent).to.equal('Person 0');
});

it('should render column correctly when text-align is defined', async () => {
const wrapper = fixtureSync(
'<grid-wrapper-delayed><vaadin-grid-column path="name" text-align="end"></vaadin-grid-column></grid-wrapper-delayed>',
);
// Delaying the definition of the custom-element so internal <vaadin-grid> is not yet defined
customElements.define('grid-wrapper-delayed', class extends GridWrapper {});

const grid = await initGrid(wrapper);

expect(getBodyCellContent(grid, 0, 0).textContent).to.equal('Person 0');
});
});