diff --git a/examples/vite-demo-vanilla-bundle/package.json b/examples/vite-demo-vanilla-bundle/package.json index 98edc3bba..cc95f6acb 100644 --- a/examples/vite-demo-vanilla-bundle/package.json +++ b/examples/vite-demo-vanilla-bundle/package.json @@ -28,7 +28,7 @@ "bulma": "^1.0.0", "dompurify": "^3.1.2", "fetch-jsonp": "^1.3.0", - "multiple-select-vanilla": "^3.1.4", + "multiple-select-vanilla": "^3.2.0", "rxjs": "^7.8.1", "vanilla-calendar-picker": "^2.11.4", "whatwg-fetch": "^3.6.20" diff --git a/packages/common/package.json b/packages/common/package.json index e8af63ad4..6bed29228 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -74,7 +74,7 @@ "autocompleter": "^9.2.1", "dequal": "^2.0.3", "excel-builder-vanilla": "3.0.1", - "multiple-select-vanilla": "^3.1.4", + "multiple-select-vanilla": "^3.2.0", "sortablejs": "^1.15.2", "un-flatten-tree": "^2.0.12", "vanilla-calendar-picker": "^2.11.4" diff --git a/packages/common/src/editors/__tests__/selectEditor.spec.ts b/packages/common/src/editors/__tests__/selectEditor.spec.ts index 122d6b6c7..3562cbf5c 100644 --- a/packages/common/src/editors/__tests__/selectEditor.spec.ts +++ b/packages/common/src/editors/__tests__/selectEditor.spec.ts @@ -631,6 +631,38 @@ describe('SelectEditor', () => { expect(saveSpy).toHaveBeenCalledWith(false); }); + it('should cancel changes when Escape key is pressed and should not call "save()"', () => { + mockItemData = { id: 1, gender: 'male', isActive: true }; + gridOptionMock.autoCommitEdit = false; + + editor = new SelectEditor(editorArguments, true); + const cancelSpy = jest.spyOn(editor, 'cancel'); + const saveSpy = jest.spyOn(editor, 'save'); + + editor.loadValue(mockItemData); + editor.msInstance?.close('key.escape'); + editor.destroy(); + + expect(cancelSpy).toHaveBeenCalled(); + expect(saveSpy).not.toHaveBeenCalled(); + }); + + it('should not "save()" when clicking ouside the select on body', () => { + mockItemData = { id: 1, gender: 'male', isActive: true }; + gridOptionMock.autoCommitEdit = false; + + editor = new SelectEditor(editorArguments, true); + const cancelSpy = jest.spyOn(editor, 'cancel'); + const saveSpy = jest.spyOn(editor, 'save'); + + editor.loadValue(mockItemData); + editor.msInstance?.close('body.click'); + editor.destroy(); + + expect(cancelSpy).not.toHaveBeenCalled(); + expect(saveSpy).not.toHaveBeenCalled(); + }); + it('should not call "commitCurrentEdit" when "hasAutoCommitEdit" is disabled', () => { mockItemData = { id: 1, gender: 'male', isActive: true }; gridOptionMock.autoCommitEdit = false; diff --git a/packages/common/src/editors/selectEditor.ts b/packages/common/src/editors/selectEditor.ts index 74d6e95ff..76b960349 100644 --- a/packages/common/src/editors/selectEditor.ts +++ b/packages/common/src/editors/selectEditor.ts @@ -124,7 +124,14 @@ export class SelectEditor implements Editor { onClick: () => this._isValueTouched = true, onCheckAll: () => this._isValueTouched = true, onUncheckAll: () => this._isValueTouched = true, - onClose: () => { + onClose: (reason) => { + if (reason === 'key.escape' || reason === 'body.click' || (!this.hasAutoCommitEdit && !this.isValueChanged())) { + if (reason === 'key.escape') { + this.cancel(); + } + return; + } + if (compositeEditorOptions) { this.handleChangeOnCompositeEditor(compositeEditorOptions); } else { @@ -364,6 +371,12 @@ export class SelectEditor implements Editor { } } + cancel() { + if (this.args?.cancelChanges) { + this.args.cancelChanges(); + } + } + hide() { if (this._msInstance) { this._msInstance.close(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 67e2be75f..958419f35 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -186,8 +186,8 @@ importers: specifier: ^1.3.0 version: 1.3.0 multiple-select-vanilla: - specifier: ^3.1.4 - version: 3.1.4 + specifier: ^3.2.0 + version: 3.2.0 rxjs: specifier: ^7.8.1 version: 7.8.1 @@ -250,8 +250,8 @@ importers: specifier: 3.0.1 version: 3.0.1 multiple-select-vanilla: - specifier: ^3.1.4 - version: 3.1.4 + specifier: ^3.2.0 + version: 3.2.0 sortablejs: specifier: ^1.15.2 version: 1.15.2 @@ -6903,8 +6903,8 @@ packages: minimatch: 9.0.4 dev: true - /multiple-select-vanilla@3.1.4: - resolution: {integrity: sha512-tYZOelEDbTl7p0hu/l1WLUWCgQuoLTT70bJQIEtO404kVbNUHKWmesF8U23jqekOL1+WlYm9cARYI8eci42g8w==} + /multiple-select-vanilla@3.2.0: + resolution: {integrity: sha512-rqsgTKbn8S0+oVYoNOBe/0P7BpimWChRf7hv42uOtZPkPSHOmNt8bDxJAGCRhT4nvOnlamaHMm0U1zQPfH9IDA==} dependencies: '@types/trusted-types': 2.0.7 dev: false