Skip to content

Commit

Permalink
fix: fixes for IE11 / Legacy Edge
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Jan 20, 2022
1 parent 409b001 commit 2e793c8
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
13 changes: 11 additions & 2 deletions src/vaadin-grid-column-reordering-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,24 @@
if (!this._draggedColumn) {
this._toggleAttribute('no-content-pointer-events', true, this.$.scroller);
}
// Workaround a ShadyDOM bug
this._reorderGhost.hidden = true;

let cell;
if (Polymer.Settings.useShadow) {
if (this.shadowRoot.elementFromPoint) {
cell = this.shadowRoot.elementFromPoint(x, y);
} else {
cell = document.elementFromPoint(x, y);
}

// Workaround a FF58 bug
this._reorderGhost.hidden = false;

// Workaround FF58/ShadyDOM bugs
while (!cell._column && cell.parentElement) {
if (cell.localName === 'vaadin-grid-cell-content') {
cell = cell.assignedSlot.parentNode;
} else {
cell = cell.parentElement;
}

}
Expand Down
6 changes: 5 additions & 1 deletion test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"env": {
"es6": true
},
"parserOptions": {
"ecmaVersion": 8
},
"rules": {
"no-unused-vars": 0
},
Expand Down Expand Up @@ -61,6 +64,7 @@
"getContainerCell": false,
"footerTrap": false,
"wheel": false,
"whenGridAppearAnimationEnd": false
"whenGridAppearAnimationEnd": false,
"nextFrame": false
}
}
23 changes: 11 additions & 12 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,15 @@
});
});

it('reorder should not affect light dom', () => {
it('reorder should not affect light dom', async() => {
grid.size = 1000;
await nextFrame();
const wrappers = grid.querySelectorAll('vaadin-grid-cell-content');

[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144].forEach(steps => {
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144].forEach(async(steps) => {
grid.$.table.scrollTop = 5000 + grid._physicalAverage * steps;
grid._scrollHandler();
grid._debounceScrolling.flush();
flushGrid(grid);
await nextFrame();

const newWrappers = grid.querySelectorAll('vaadin-grid-cell-content');
// Expect the light dom order unchanged
Expand Down Expand Up @@ -377,16 +378,14 @@
expect(grid.$.scroller.getBoundingClientRect().width).to.be.closeTo(300 - 2, 1);
});

it('should have a visible header after row reorder', done => {
it('should have a visible header after row reorder', async() => {
grid.querySelector('vaadin-grid-column').header = 'header';
grid.scrollToIndex(300);
setTimeout(() => {
flushGrid(grid);
const {left, top} = grid.getBoundingClientRect();
const cell = grid._cellFromPoint(left + 1, top + 1);
expect(grid.$.header.contains(cell)).to.be.true;
done();
});
await nextFrame();
flushGrid(grid);
const {left, top} = grid.getBoundingClientRect();
const cell = grid._cellFromPoint(left + 1, top + 1);
expect(grid.$.header.contains(cell)).to.be.true;
});

// Skip this test on iOS 10 since there Safari has a bug that makes this fail (works in iOS 9, 11 and 12)
Expand Down
10 changes: 7 additions & 3 deletions test/column-resizing.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
});

function getElementFromPoint(context, x, y) {
if (Polymer.Settings.useShadow) {
if (context.shadowRoot.elementFromPoint) {
return context.shadowRoot.elementFromPoint(x, y);
} else {
return document.elementFromPoint(x, y);
Expand Down Expand Up @@ -176,20 +176,24 @@
expect(grid.$.scroller.hasAttribute('resizing')).to.be.false;
});

it('should not fix width for succeeding columns', () => {
it('should not fix width for succeeding columns', async() => {
grid._columnTree[0][1].width = '50%';
grid._columnTree[0][1].flexGrow = 1;
await nextFrame();
fire('track', {state: 'start'}, {node: handle});
await nextFrame();
expect(grid._columnTree[0][1].width).to.equal('50%');
expect(grid._columnTree[0][1].flexGrow).to.equal(1);
});

it('should fix width for preceding columns', () => {
it('should fix width for preceding columns', async() => {
grid._columnTree[0][1].resizable = true;

grid._columnTree[0][0].width = '50%';
grid._columnTree[0][0].flexGrow = 1;
await nextFrame();
fire('track', {state: 'start'}, {node: headerCells[1].querySelector('[part~="resize-handle"]')});
await nextFrame();
expect(grid._columnTree[0][0].width.indexOf('px')).not.to.equal(-1);
expect(grid._columnTree[0][0].flexGrow).to.equal(0);
});
Expand Down
2 changes: 1 addition & 1 deletion test/data-provider.html
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@

// Test actual last visible item
const rect = grid.getBoundingClientRect();
const scope = Polymer.Settings.useShadow ? grid.domHost.root : document;
const scope = grid.domHost.root.elementFromPoint ? grid.domHost.root : document;
const lastVisibleItem = scope.elementFromPoint(rect.left + 15, rect.bottom - 15);
expect(lastVisibleItem.innerText.trim()).to.equal('foo' + (grid.size - 1));
});
Expand Down
4 changes: 4 additions & 0 deletions test/helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,8 @@
return event;
};

window.nextFrame = () => {
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
};

</script>
2 changes: 1 addition & 1 deletion test/scroll-to-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
grid.scrollToIndex(targetIndex);

const rect = grid.$.header.getBoundingClientRect();
const cell = (Polymer.Settings.useShadow ? grid.shadowRoot : document).elementFromPoint(rect.left + 1, rect.bottom + 2);
const cell = (grid.shadowRoot.elementFromPoint ? grid.shadowRoot : document).elementFromPoint(rect.left + 1, rect.bottom + 2);
expect(cell.parentElement.index).to.equal(targetIndex);
});

Expand Down

0 comments on commit 2e793c8

Please sign in to comment.