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 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
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
56 changes: 56 additions & 0 deletions packages/grid/test/grid-wrapper.test.js
tomivirkki marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import '../vaadin-grid.js';
import '../vaadin-grid-column-group.js';
import '../vaadin-grid-column.js';
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
import { flushGrid } from './helpers.js';

class GridWrapper extends PolymerElement {
static get template() {
return html`
<vaadin-grid id="grid">
<vaadin-grid-column-group>
<slot name="group"></slot>
</vaadin-grid-column-group>
<slot></slot>
</vaadin-grid>
`;
}
}
tomivirkki marked this conversation as resolved.
Show resolved Hide resolved

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

describe('columns slotted in custom element', () => {
let spy;
beforeEach(() => {
spy = sinon.spy(console, 'error');
});

afterEach(() => {
spy.restore();
});

it('should not throw if column with auto-width is defined', () => {
fixtureSync('<grid-wrapper><vaadin-grid-column path="name" auto-width></vaadin-grid-column></grid-wrapper>');

expect(spy.called).to.be.false;
});

it('should not throw if column inside group with auto-width is defined', () => {
fixtureSync(
'<grid-wrapper><vaadin-grid-column slot="group" path="name" auto-width></vaadin-grid-column></grid-wrapper>',
);
expect(spy.called).to.be.false;
});

it('should not throw if column with text-align is defined', () => {
fixtureSync(
'<grid-wrapper-delayed><vaadin-grid-column 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 {});
expect(spy.called).to.be.false;
});
});