Skip to content

Commit

Permalink
fix: exit edit mode when a cell becomes non-editable (#7361)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Apr 25, 2024
1 parent 706b40c commit 178d0e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/grid-pro/src/vaadin-grid-pro-inline-editing-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,15 @@ export const InlineEditingMixin = (superClass) =>
}
// Otherwise, check isCellEditable function
const model = this.__getRowModel(cell.parentElement);
return column.isCellEditable(model);
const isEditable = column.isCellEditable(model);

// Cancel editing if the cell is currently edited one and becomes no longer editable
// TODO: should be moved to `_updateItem` when Grid connector is updated to use it.
if (this.__edited && this.__edited.cell === cell && !isEditable) {
this._stopEdit(true, true);
}

return isEditable;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/grid-pro/test/edit-column.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ describe('edit column', () => {
expect(isCellEditable(1, 2)).to.be.true;
});

it('should stop editing when cell becomes non-editable after updating provider function', async () => {
// Enable editing
amountColumn.isCellEditable = () => true;
const cell = getContainerCell(grid.$.items, 1, 2);
enter(cell);
expect(getCellEditor(cell)).to.be.ok;
// Disable editing
amountColumn.isCellEditable = () => false;
await nextFrame();
expect(getCellEditor(cell)).to.be.not.ok;
});

it('should not add editable-cell part to non-editable cells', () => {
expect(hasEditablePart(0, 0)).to.be.false;
expect(hasEditablePart(0, 1)).to.be.true;
Expand Down

0 comments on commit 178d0e0

Please sign in to comment.