-
Notifications
You must be signed in to change notification settings - Fork 94
fix: make conditional editing work with lazy columns #11405
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
Changes from all commits
9dd945e
f4f5fcc
35bd875
8e5c828
44d0903
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an error that happens in Firefox and Safari when you scroll away from the column while the editor is active, so that the column is detached, and then scroll back to the same column and try to open the editor on the same cell again. That seems to happen because grid-edit-firefox.mp4
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like those browsers don't fire The added tests only covers Safari, as Playwright Firefox does fire
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I recall facing this same limitation in another issue (maybe also related to grid-pro 🤔). I can't see the issue anymore. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,16 @@ | ||
| import { expect } from '@vaadin/chai-plugins'; | ||
| import { sendKeys } from '@vaadin/test-runner-commands'; | ||
| import { enter, esc, fixtureSync, focusin, focusout, nextFrame } from '@vaadin/testing-helpers'; | ||
| import { | ||
| aTimeout, | ||
| enter, | ||
| esc, | ||
| fixtureSync, | ||
| focusin, | ||
| focusout, | ||
| isFirefox, | ||
| nextFrame, | ||
| oneEvent, | ||
| } from '@vaadin/testing-helpers'; | ||
| import sinon from 'sinon'; | ||
| import './not-animated-styles.js'; | ||
| import '../src/vaadin-grid-pro.js'; | ||
|
|
@@ -10,6 +20,7 @@ | |
| dblclick, | ||
| flatMap, | ||
| flushGrid, | ||
| getCellContent, | ||
| getCellEditor, | ||
| getContainerCell, | ||
| getRowCells, | ||
|
|
@@ -570,6 +581,111 @@ | |
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('lazy column rendering', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In line 542 of the This test fails without the suggested change. it('should stop editing when item identity changes for a detached edited cell', async () => {
let cell = getCellByColumnPath('col1');
cell.focus();
await sendKeys({ press: 'Enter' });
expect(getCellEditor(cell)).to.be.ok;
// Scroll far right so col1 cell gets detached from the DOM
await scrollHorizontally(400);
// Change the item identity for the edited row
grid.items = [
{ col0: 'x0', col1: 'x1', col2: 'x2', col3: 'x3', col4: 'x4', col5: 'x5', col6: 'x6', col7: 'x7' },
{ col0: 'b0', col1: 'b1', col2: 'b2', col3: 'b3', col4: 'b4', col5: 'b5', col6: 'b6', col7: 'b7' },
];
flushGrid(grid);
// The edit should be stopped because the item identity changed
expect(getCellEditor(cell)).to.not.be.ok;
});
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated it to use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works now |
||
| const UPDATE_CONTENT_VISIBILITY_DEBOUNCER_TIMEOUT = 100; | ||
|
|
||
| async function scrollHorizontally(delta) { | ||
| grid.$.table.scrollLeft += delta; | ||
| await oneEvent(grid.$.table, 'scroll'); | ||
| await aTimeout(UPDATE_CONTENT_VISIBILITY_DEBOUNCER_TIMEOUT); | ||
| } | ||
|
|
||
| function getCellByColumnPath(columnPath) { | ||
|
Check warning on line 594 in packages/grid-pro/test/edit-column.test.js
|
||
| const row = getRows(grid.$.items)[0]; | ||
| const cells = getRowCells(row); | ||
| const cell = cells.find((c) => c._column.path === columnPath); | ||
| expect(cell, `Could not find cell for column with path ${columnPath}`).to.be.ok; | ||
|
|
||
| return cell; | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| grid = fixtureSync(`<vaadin-grid-pro style="width: 400px;"></vaadin-grid-pro>`); | ||
|
|
||
| const columns = []; | ||
| for (let i = 0; i < 8; i++) { | ||
| const column = document.createElement('vaadin-grid-pro-edit-column'); | ||
| column.path = `col${i}`; | ||
| column.header = `Col ${i}`; | ||
| column.width = '100px'; | ||
| column.flexGrow = 0; | ||
| columns.push(column); | ||
| grid.appendChild(column); | ||
| } | ||
|
|
||
| grid.items = [ | ||
| { col0: 'a0', col1: 'a1', col2: 'a2', col3: 'a3', col4: 'a4', col5: 'a5', col6: 'a6', col7: 'a7' }, | ||
| { col0: 'b0', col1: 'b1', col2: 'b2', col3: 'b3', col4: 'b4', col5: 'b5', col6: 'b6', col7: 'b7' }, | ||
| ]; | ||
|
|
||
| // Make odd-indexed columns conditionally editable | ||
| columns.forEach((column, i) => { | ||
| column.isCellEditable = () => i % 2 === 1; | ||
| }); | ||
|
|
||
| grid.columnRendering = 'lazy'; | ||
| flushGrid(grid); | ||
| }); | ||
|
|
||
| it('should mark initially visible cells as non-editable based on isCellEditable', () => { | ||
| expect(hasEditablePart(0, 0)).to.be.false; | ||
| expect(hasEditablePart(0, 1)).to.be.true; | ||
| }); | ||
|
|
||
| it('should mark lazily rendered cells as non-editable based on isCellEditable after scrolling', async () => { | ||
| // Scroll far enough to reveal the last columns | ||
| await scrollHorizontally(400); | ||
|
|
||
| const cells = getRowCells(getRows(grid.$.items)[0]); | ||
|
|
||
| // Verify we are testing correct cells | ||
| expect(getCellContent(cells[cells.length - 2]).textContent).to.equal('a6'); | ||
| expect(getCellContent(cells[cells.length - 1]).textContent).to.equal('a7'); | ||
|
|
||
| expect(hasEditablePart(0, cells.length - 2)).to.be.false; | ||
| expect(hasEditablePart(0, cells.length - 1)).to.be.true; | ||
| }); | ||
|
|
||
| // Focus button mode that is active on MacOS causes issues with Tab key navigation in Firefox when run with Playwright | ||
| (isFirefox && isMac ? it.skip : it)('should navigate through editable cells with Tab', async () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to skip this one on FF / Mac, looks like there is an unrelated issue with the focus button mode in keyboard navigation mixin that can also be observed in some scenarios when testing manually on |
||
| let cell = getCellByColumnPath('col1'); | ||
| cell.focus(); | ||
| await sendKeys({ press: 'Enter' }); | ||
| expect(getCellEditor(cell)).to.be.ok; | ||
|
|
||
| await sendKeys({ press: 'Tab' }); | ||
| cell = getCellByColumnPath('col3'); | ||
| expect(getCellEditor(cell)).to.be.ok; | ||
|
|
||
| await sendKeys({ press: 'Tab' }); | ||
| cell = getCellByColumnPath('col5'); | ||
| expect(getCellEditor(cell)).to.be.ok; | ||
|
|
||
| await sendKeys({ press: 'Tab' }); | ||
| cell = getCellByColumnPath('col7'); | ||
| expect(getCellEditor(cell)).to.be.ok; | ||
| }); | ||
|
|
||
| it('should edit cell again after it was temporarily removed due to scrolling', async () => { | ||
| const cell = getCellByColumnPath('col1'); | ||
| cell.focus(); | ||
| await sendKeys({ press: 'Enter' }); | ||
| expect(getCellEditor(cell)).to.be.ok; | ||
|
|
||
| await scrollHorizontally(500); | ||
|
|
||
| expect(cell.isConnected).to.be.false; | ||
|
|
||
| await scrollHorizontally(-500); | ||
|
|
||
| expect(getCellEditor(cell)).to.not.be.ok; | ||
|
|
||
| cell.focus(); | ||
| await sendKeys({ press: 'Enter' }); | ||
| expect(getCellEditor(cell)).to.be.ok; | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('vertical scrolling', () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.