Skip to content
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
5 changes: 2 additions & 3 deletions packages/grid-pro/test/keyboard-navigation.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
import { sendKeys } from '@vaadin/test-runner-commands';
import { aTimeout, fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import { aTimeout, fixtureSync, nextFrame, nextResize } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import '../src/vaadin-grid-pro.js';
import '../src/vaadin-grid-pro-edit-column.js';
Expand Down Expand Up @@ -30,8 +30,7 @@ describe('keyboard navigation', () => {
};

grid.items = createItems();
// Wait for vaadin-grid-appear animation to finish
await oneEvent(grid, 'animationend');
await nextResize(grid);
flushGrid(grid);
});

Expand Down
7 changes: 0 additions & 7 deletions packages/grid/src/styles/vaadin-grid-base-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ import '@vaadin/component-base/src/styles/style-props.js';
import { css } from 'lit';

export const gridStyles = css`
@keyframes vaadin-grid-appear {
to {
opacity: 1;
}
}

:host {
display: flex;
animation: 1ms vaadin-grid-appear;
max-width: 100%;
height: 400px;
min-height: var(--_grid-min-height, 0);
Expand Down
12 changes: 5 additions & 7 deletions packages/grid/src/vaadin-grid-column-auto-width-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ export const ColumnAutoWidthMixin = (superClass) =>
];
}

constructor() {
super();
this.addEventListener('animationend', this.__onAnimationEndAutoWidth);
}
/** @protected */
updated(props) {
super.updated(props);

/** @private */
__onAnimationEndAutoWidth(e) {
if (e.animationName.indexOf('vaadin-grid-appear') === 0) {
// If the grid was hidden and is now visible
if (props.has('__hostVisible') && !props.get('__hostVisible')) {
this.__tryToRecalculateColumnWidthsIfPending();
}
}
Expand Down
28 changes: 8 additions & 20 deletions packages/grid/src/vaadin-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ export const GridMixin = (superClass) =>
};
}

constructor() {
super();
this.addEventListener('animationend', this._onAnimationEnd);
}

/** @private */
get _firstVisibleIndex() {
const firstVisibleItem = this.__getFirstVisibleItem();
Expand Down Expand Up @@ -279,6 +274,14 @@ export const GridMixin = (superClass) =>
updated(props) {
super.updated(props);

// If the grid was hidden and is now visible
if (props.has('__hostVisible') && !props.get('__hostVisible')) {
// Ensure header and footer have tabbable elements
this._resetKeyboardNavigation();

requestAnimationFrame(() => this.__scrollToPendingIndexes());
}

if (props.has('__headerRect') || props.has('__footerRect') || props.has('__itemsRect')) {
setTimeout(() => this.__updateMinHeight());
}
Expand Down Expand Up @@ -824,21 +827,6 @@ export const GridMixin = (superClass) =>
this.__updateHorizontalScrollPosition();
}

/** @private */
_onAnimationEnd(e) {
// ShadyCSS applies scoping suffixes to animation names
if (e.animationName.indexOf('vaadin-grid-appear') === 0) {
e.stopPropagation();

// Ensure header and footer have tabbable elements
this._resetKeyboardNavigation();

requestAnimationFrame(() => {
this.__scrollToPendingIndexes();
});
}
}

/**
* @param {!HTMLTableRowElement} row
* @return {!GridItemModel}
Expand Down
12 changes: 12 additions & 0 deletions packages/grid/src/vaadin-grid-resize-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export const ResizeMixin = (superClass) =>
class extends superClass {
static get properties() {
return {
/** @private */
__hostVisible: {
type: Boolean,
value: false,
},

/** @private */
__tableRect: Object,

Expand All @@ -32,6 +38,11 @@ export const ResizeMixin = (superClass) =>
super.ready();

const resizeObserver = new ResizeObserver((entries) => {
const hostEntry = entries.findLast(({ target }) => target === this);
if (hostEntry) {
this.__hostVisible = this.checkVisibility();
}

const tableEntry = entries.findLast(({ target }) => target === this.$.table);
if (tableEntry) {
this.__tableRect = tableEntry.contentRect;
Expand All @@ -53,6 +64,7 @@ export const ResizeMixin = (superClass) =>
}
});

resizeObserver.observe(this);
resizeObserver.observe(this.$.table);
resizeObserver.observe(this.$.header);
resizeObserver.observe(this.$.items);
Expand Down
10 changes: 4 additions & 6 deletions packages/grid/test/column-auto-width.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
import { aTimeout, fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import { aTimeout, fixtureSync, nextFrame, nextResize } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import './grid-test-styles.js';
import '../all-imports.js';
Expand Down Expand Up @@ -79,10 +79,8 @@ describe('column auto-width', () => {
`);
spy = sinon.spy(grid, '_recalculateColumnWidths');
columns = grid.querySelectorAll('vaadin-grid-column');
// Show the grid and wait for animationend event ("vaadin-grid-appear")
// to ensure the grid is in a consistent state before starting each test
grid.hidden = false;
await oneEvent(grid, 'animationend');
await nextResize(grid);
});

it('should have correct column widths when items are set', async () => {
Expand Down Expand Up @@ -188,9 +186,9 @@ describe('column auto-width', () => {
</vaadin-grid>
`);

await nextFrame();
await nextResize(grid);
grid.hidden = false;
await oneEvent(grid, 'animationend');
await nextResize(grid);
expectColumnWidthsToBeOk(grid.querySelectorAll('vaadin-grid-column'), [107]);
});

Expand Down
6 changes: 3 additions & 3 deletions packages/grid/test/drag-and-drop.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
import { resetMouse, sendMouse, sendMouseToElement } from '@vaadin/test-runner-commands';
import { aTimeout, fixtureSync, listenOnce, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import { aTimeout, fixtureSync, listenOnce, nextFrame, nextResize } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import './grid-test-styles.js';
import '../src/vaadin-grid.js';
Expand Down Expand Up @@ -114,9 +114,9 @@ describe('drag and drop', () => {
<vaadin-grid-column path="last" header="Last name"></vaadin-grid-column>
</vaadin-grid>
`);
await nextFrame();
await nextResize(grid);
grid.hidden = false;
await oneEvent(grid, 'animationend');
await nextResize(grid);
await aTimeout(1);

dragData = {};
Expand Down
6 changes: 3 additions & 3 deletions packages/grid/test/hidden-grid.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
import { sendKeys } from '@vaadin/test-runner-commands';
import { fixtureSync, nextFrame, nextRender, oneEvent } from '@vaadin/testing-helpers';
import { fixtureSync, nextFrame, nextRender, nextResize } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import './grid-test-styles.js';
import '../src/vaadin-grid.js';
Expand Down Expand Up @@ -31,14 +31,14 @@ describe('hidden grid', () => {

it('should have content on appear', async () => {
grid.removeAttribute('hidden');
await oneEvent(grid, 'animationend');
await nextResize(grid);
await nextFrame();
expect(getBodyCellContent(grid, 0, 0).textContent).to.equal('0');
});

it('should make it possible to Tab to header', async () => {
grid.removeAttribute('hidden');
await oneEvent(grid, 'animationend');
await nextResize(grid);
await nextFrame();

await sendKeys({ press: 'Tab' });
Expand Down
6 changes: 3 additions & 3 deletions packages/grid/test/resizing.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
import { aTimeout, fixtureSync, nextFrame, nextResize, oneEvent } from '@vaadin/testing-helpers';
import { aTimeout, fixtureSync, nextFrame, nextResize } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import './grid-test-styles.js';
import '../all-imports.js';
Expand Down Expand Up @@ -38,9 +38,9 @@ describe('resizing', () => {
root.textContent = 'footer';
};
grid.dataProvider = infiniteDataProvider;
await nextFrame();
await nextResize(grid);
grid.hidden = false;
await oneEvent(grid, 'animationend');
await nextResize(grid);
flushGrid(grid);
});

Expand Down
6 changes: 3 additions & 3 deletions packages/grid/test/row-height.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
import { aTimeout, fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import { aTimeout, fixtureSync, nextFrame, nextResize } from '@vaadin/testing-helpers';
import './grid-test-styles.js';
import '../src/vaadin-grid.js';
import { flushGrid, getRowCells, getRows, infiniteDataProvider, scrollToEnd } from './helpers.js';
Expand Down Expand Up @@ -54,14 +54,14 @@ describe('rows', () => {
async function init(fixtureFactory) {
grid = fixtureFactory();

await nextFrame();
await nextResize(grid);

grid.dataProvider = infiniteDataProvider;
grid.hidden = false;
flushGrid(grid);
header = grid.$.header;

await oneEvent(grid, 'animationend');
await nextResize(grid);
flushGrid(grid);

rows = getRows(grid.$.items);
Expand Down
21 changes: 9 additions & 12 deletions packages/grid/test/scroll-to-index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
import { fixtureSync, listenOnce, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import { fixtureSync, listenOnce, nextFrame, nextResize } from '@vaadin/testing-helpers';
import './grid-test-styles.js';
import '../all-imports.js';
import {
Expand Down Expand Up @@ -149,18 +149,15 @@ describe('scroll to index', () => {
grid.scrollToIndex(49, 100);
});

it('should scroll to index after attaching', (done) => {
it('should scroll to index after attaching', async () => {
const parent = grid.parentElement;
parent.removeChild(grid);
grid.scrollToIndex(100);
grid.addEventListener('animationend', () => {
requestAnimationFrame(() => {
expect(getFirstVisibleItem(grid).index).to.be.above(75);
expect(grid.$.table.scrollTop).to.be.above(0);
done();
});
});
parent.appendChild(grid);
await nextResize(grid);
await nextFrame();
expect(getFirstVisibleItem(grid).index).to.be.above(75);
expect(grid.$.table.scrollTop).to.be.above(0);
});

it('should scroll to index after unhiding', async () => {
Expand Down Expand Up @@ -325,7 +322,7 @@ describe('scroll to index', () => {
flushGrid(grid);
flushPendingRequests();

await oneEvent(grid, 'animationend');
await nextResize(grid);
await nextFrame();
});

Expand Down Expand Up @@ -570,7 +567,7 @@ describe('scroll to index', () => {
`);
grid.items = Array.from({ length: 100 }, (_, index) => `Item ${index}`);
grid.scrollToIndex(50);
await oneEvent(grid, 'animationend');
await nextResize(grid);
await nextFrame();
});

Expand All @@ -590,7 +587,7 @@ describe('scroll to index', () => {
grid.items = Array.from({ length: 100 }, (_, index) => `Item ${index}`);
grid.scrollToIndex(50);
container.appendChild(grid);
await oneEvent(grid, 'animationend');
await nextResize(grid);
await nextFrame();
});

Expand Down
7 changes: 0 additions & 7 deletions packages/vaadin-lumo-styles/src/components/grid.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
@media lumo_components_grid {
@keyframes vaadin-grid-appear {
to {
opacity: 1;
}
}

:host {
display: flex;
flex-direction: column;
animation: 1ms vaadin-grid-appear;
height: 400px;
min-height: var(--_grid-min-height, 0);
flex: 1 1 auto;
Expand Down