Skip to content

Commit

Permalink
fix: we shouldn't always commit on focusout/blur (#1192)
Browse files Browse the repository at this point in the history
- always committing as soon as we do focusout/blur is a little extreme since in some cases we for example clicking on an editor with a picker is closing the picker before we even a chance to choose anything
  • Loading branch information
ghiscoding committed May 7, 2024
1 parent 27ee287 commit 5b9b543
Showing 1 changed file with 1 addition and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,19 @@ import { SlickRowDetailView } from '../extensions/slickRowDetailView';

@customElement({
name: 'aurelia-slickgrid',
/* eslint-disable */
template: `
<div id="slickGridContainer-$\{gridId\}" class="grid-pane">
<!-- Header slot if you need to create a complex custom header -->
<au-slot name="slickgrid-header"></au-slot>
<div id.bind="gridId" class="slickgrid-container" focusout.trigger="commitEdit($event.target)"
<div id.bind="gridId" class="slickgrid-container"
ref="gridContainer">
</div>
<!-- Footer slot if you need to create a complex custom footer -->
<au-slot name="slickgrid-footer"></au-slot>
</div>
` })
/* eslint-enable */
export class AureliaSlickgridCustomElement {
protected _columnDefinitions: Column[] = [];
protected _currentDatasetLength = 0;
Expand Down Expand Up @@ -589,28 +587,6 @@ export class AureliaSlickgridCustomElement {
this.observeColumnDefinitions();
}

/**
* Commits the current edit to the grid
*/
commitEdit(target: Element) {
if (this.grid.getOptions().autoCommitEdit) {
const activeNode = this.grid.getActiveCellNode();

// a timeout must be set or this could come into conflict when slickgrid
// tries to commit the edit when going from one editor to another on the grid
// through the click event. If the timeout was not here it would
// try to commit/destroy the twice, which would throw an
// error about the element not being in the DOM
setTimeout(() => {
// make sure the target is the active editor so we do not
// commit prematurely
if (activeNode?.contains(target) && this.grid.getEditorLock().isActive() && !target?.classList?.contains('autocomplete')) {
this.grid.getEditorLock().commitCurrentEdit();
}
});
}
}

datasetChanged(newDataset: any[], oldValue: any[]) {
const prevDatasetLn = this._currentDatasetLength;
const isDatasetEqual = dequal(newDataset, this._dataset || []);
Expand Down

0 comments on commit 5b9b543

Please sign in to comment.