|
| 1 | +import { expect } from '@esm-bundle/chai'; |
| 2 | +import { aTimeout, fixtureSync, isFirefox } from '@vaadin/testing-helpers'; |
| 3 | +import '../vaadin-grid.js'; |
| 4 | +import { fire, flushGrid, infiniteDataProvider } from './helpers.js'; |
| 5 | + |
| 6 | +if (isFirefox) { |
| 7 | + // This suite tests a fix for an issue in Firefox where switching visibility |
| 8 | + // of two grids causes the scroll position of the first grid to be reset to 0, |
| 9 | + // and the scroll position of the second grid is synchronized from the first |
| 10 | + // grid. |
| 11 | + // See https://github.com/vaadin/web-components/issues/5796 |
| 12 | + describe('scroll restoration in Firefox', () => { |
| 13 | + let grid1, grid2; |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + const fixture = fixtureSync(` |
| 17 | + <div> |
| 18 | + <vaadin-grid style="height: 200px; width: 200px;" size="100"> |
| 19 | + <vaadin-grid-column header="foo"></vaadin-grid-column> |
| 20 | + </vaadin-grid> |
| 21 | + <vaadin-grid style="height: 200px; width: 200px;" hidden size="100"> |
| 22 | + <vaadin-grid-column header="bar"></vaadin-grid-column> |
| 23 | + </vaadin-grid> |
| 24 | + </div> |
| 25 | + `); |
| 26 | + const grids = fixture.querySelectorAll('vaadin-grid'); |
| 27 | + grids.forEach((grid) => { |
| 28 | + grid.querySelector('vaadin-grid-column').renderer = (root, _, model) => { |
| 29 | + root.textContent = model.index; |
| 30 | + }; |
| 31 | + grid.dataProvider = infiniteDataProvider; |
| 32 | + flushGrid(grid); |
| 33 | + }); |
| 34 | + grid1 = grids[0]; |
| 35 | + grid2 = grids[1]; |
| 36 | + }); |
| 37 | + |
| 38 | + function toggleVisibility() { |
| 39 | + grid1.hidden = !grid1.hidden; |
| 40 | + grid2.hidden = !grid2.hidden; |
| 41 | + } |
| 42 | + |
| 43 | + it('should restore scroll position when showing grids', async () => { |
| 44 | + // Scroll grid |
| 45 | + grid1.$.table.scrollTop = 300; |
| 46 | + fire('scroll', {}, { node: grid1.$.table }); |
| 47 | + flushGrid(grid1); |
| 48 | + await aTimeout(50); |
| 49 | + |
| 50 | + // Hide first grid, show second grid |
| 51 | + toggleVisibility(); |
| 52 | + await aTimeout(50); |
| 53 | + |
| 54 | + // Hide second grid, show first grid again |
| 55 | + toggleVisibility(); |
| 56 | + await aTimeout(50); |
| 57 | + |
| 58 | + // Scroll position for first grid should still be 300 |
| 59 | + expect(grid1.$.table.scrollTop).to.equal(300); |
| 60 | + |
| 61 | + // Show second grid again |
| 62 | + toggleVisibility(); |
| 63 | + await aTimeout(50); |
| 64 | + |
| 65 | + // Scroll position for first grid should still be 0 |
| 66 | + expect(grid2.$.table.scrollTop).to.equal(0); |
| 67 | + }); |
| 68 | + }); |
| 69 | +} |
0 commit comments