diff --git a/packages/common/src/core/__tests__/slickGrid.spec.ts b/packages/common/src/core/__tests__/slickGrid.spec.ts index 305832902..15c5311e4 100644 --- a/packages/common/src/core/__tests__/slickGrid.spec.ts +++ b/packages/common/src/core/__tests__/slickGrid.spec.ts @@ -1159,6 +1159,15 @@ describe('SlickGrid core file', () => { expect(rowSelectSpy).toHaveBeenCalled(); }); + + it('should clear previous selection model when calling setSelectionModel() with a different model', () => { + const cellSelectionModel = new SlickCellSelectionModel(); + + grid = new SlickGrid(container, [], columns, { ...defaultOptions, darkMode: true }); + cellSelectionModel.init(grid); + + expect(cellSelectionModel.cellRangeSelector.addonOptions.selectionCss).toBe('2px solid white'); + }); }); describe('Node Getters', () => { diff --git a/packages/common/src/extensions/slickCellSelectionModel.ts b/packages/common/src/extensions/slickCellSelectionModel.ts index 5be04a1a6..6acd03872 100644 --- a/packages/common/src/extensions/slickCellSelectionModel.ts +++ b/packages/common/src/extensions/slickCellSelectionModel.ts @@ -32,7 +32,7 @@ export class SlickCellSelectionModel implements SelectionModel { this._eventHandler = new SlickEventHandler(); this._selector = (options === undefined || options.cellRangeSelector === undefined) - ? new SlickCellRangeSelector({ selectionCss: { border: `2px solid ${this._grid.getOptions().darkMode ? "white" : "black"}` } as CSSStyleDeclaration }) + ? new SlickCellRangeSelector({ selectionCss: { border: '2px solid black' } as CSSStyleDeclaration }) : options.cellRangeSelector; this._addonOptions = options; @@ -52,6 +52,10 @@ export class SlickCellSelectionModel implements SelectionModel { init(grid: SlickGrid): void { this._grid = grid; + if (this._addonOptions === undefined || this._addonOptions.cellRangeSelector === undefined) { + this._selector = new SlickCellRangeSelector({ selectionCss: { border: `2px solid ${this._grid.getOptions().darkMode ? "white" : "black"}` } as CSSStyleDeclaration }) + } + if (grid.hasDataView()) { this._dataView = grid.getData(); }