diff --git a/common/changes/@visactor/vtable-plugins/fix-issue-5140-add-row-column-plugin-release_2026-05-25-17-05.json b/common/changes/@visactor/vtable-plugins/fix-issue-5140-add-row-column-plugin-release_2026-05-25-17-05.json new file mode 100644 index 000000000..0bd03c688 --- /dev/null +++ b/common/changes/@visactor/vtable-plugins/fix-issue-5140-add-row-column-plugin-release_2026-05-25-17-05.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@visactor/vtable-plugins", + "comment": "Fix an issue where `AddRowColumnPlugin.release()` threw when only row or column controls were enabled (GitHub #5140)", + "type": "patch" + } + ], + "packageName": "@visactor/vtable-plugins", + "email": "892739385@qq.com" +} \ No newline at end of file diff --git a/packages/vtable-plugins/__tests__/add-row-column-plugin.test.ts b/packages/vtable-plugins/__tests__/add-row-column-plugin.test.ts new file mode 100644 index 000000000..68dbcc748 --- /dev/null +++ b/packages/vtable-plugins/__tests__/add-row-column-plugin.test.ts @@ -0,0 +1,47 @@ +// @ts-nocheck +import { ListTable } from '@visactor/vtable'; +import { AddRowColumnPlugin } from '../src'; +import { createDiv } from '../../vtable/__tests__/dom'; + +global.__VERSION__ = 'none'; + +describe('AddRowColumnPlugin release - issue #5140', () => { + const columns = [ + { field: 'id', title: 'ID', width: 120 }, + { field: 'name', title: 'Name', width: 160 } + ]; + const records = [ + { id: 1, name: 'Alice' }, + { id: 2, name: 'Bob' } + ]; + + function createTable(pluginOptions) { + const container = createDiv(); + container.style.position = 'relative'; + container.style.width = '600px'; + container.style.height = '400px'; + + return new ListTable({ + container, + columns, + records, + plugins: [new AddRowColumnPlugin(pluginOptions)] + }); + } + + afterEach(() => { + document.body.innerHTML = ''; + }); + + test('release should not throw when row controls are disabled', () => { + const table = createTable({ addRowEnable: false }); + + expect(() => table.release()).not.toThrow(); + }); + + test('release should not throw when column controls are disabled', () => { + const table = createTable({ addColumnEnable: false }); + + expect(() => table.release()).not.toThrow(); + }); +}); diff --git a/packages/vtable-plugins/src/add-row-column.ts b/packages/vtable-plugins/src/add-row-column.ts index 485608a80..2ca92b178 100644 --- a/packages/vtable-plugins/src/add-row-column.ts +++ b/packages/vtable-plugins/src/add-row-column.ts @@ -457,13 +457,13 @@ export class AddRowColumnPlugin implements pluginsDefinition.IVTablePlugin { } // #endregion release() { - this.leftDotForAddColumn.remove(); - this.rightDotForAddColumn.remove(); - this.addIconForAddColumn.remove(); - this.addLineForAddColumn.remove(); - this.topDotForAddRow.remove(); - this.bottomDotForAddRow.remove(); - this.addIconForAddRow.remove(); - this.addLineForAddRow.remove(); + this.leftDotForAddColumn?.remove(); + this.rightDotForAddColumn?.remove(); + this.addIconForAddColumn?.remove(); + this.addLineForAddColumn?.remove(); + this.topDotForAddRow?.remove(); + this.bottomDotForAddRow?.remove(); + this.addIconForAddRow?.remove(); + this.addLineForAddRow?.remove(); } }