Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheets-data-validation-ui): keep dropdown open for merged cells (#8200)

wpxp123456c0053df30e88
diff --git a/packages/sheets-data-validation-ui/src/services/__tests__/dropdown-manager.service.spec.ts b/packages/sheets-data-validation-ui/src/services/__tests__/dropdown-manager.service.spec.ts
index 066b461016..efb421e4cf 100644
--- a/packages/sheets-data-validation-ui/src/services/__tests__/dropdown-manager.service.spec.ts
+++ b/packages/sheets-data-validation-ui/src/services/__tests__/dropdown-manager.service.spec.ts
@@ -597,6 +597,38 @@ describe('DataValidationDropdownManagerService', () => {
expect(getDropdown(testBed).props).not.toHaveProperty('defaultValue');
});
+ it('keeps the active dropdown when a merged selection reports a covered cell as primary', () => {
+ testBed = createTestBed();
+ setRule(testBed, {
+ uid: 'rule-merged-list',
+ type: 'list',
+ }, {
+ dropdownType: DataValidatorDropdownType.LIST,
+ getListWithColor: () => [{ label: 'Open' }],
+ });
+
+ const worksheet = testBed.workbook.getActiveSheet()!;
+ worksheet.setMergeData([{ startRow: 1, endRow: 2, startColumn: 2, endColumn: 3 }]);
+
+ let hideCount = 0;
+ testBed.get(DataValidationDropdownManagerService).showDataValidationDropdown('book-1', 'sheet-1', 1, 2, () => {
+ hideCount++;
+ });
+
+ // Selecting a merged cell puts the primary on the clicked covered cell, not the merge main cell.
+ (testBed.get(SheetsSelectionsService) as unknown as TestSheetsSelectionsService).moveEnd([{
+ primary: {
+ unitId: 'book-1',
+ sheetId: 'sheet-1',
+ actualRow: 2,
+ actualColumn: 3,
+ },
+ } as never]);
+
+ expect(testBed.get(DataValidationDropdownManagerService).activeDropdown).not.toBeNull();
+ expect(hideCount).toBe(0);
+ });
+
it('hides the active dropdown when selection leaves validation cells', () => {
testBed = createTestBed();
setRule(testBed, {
diff --git a/packages/sheets-data-validation-ui/src/services/dropdown-manager.service.ts b/packages/sheets-data-validation-ui/src/services/dropdown-manager.service.ts
index 71e00560e1..d2bd70e46e 100644
--- a/packages/sheets-data-validation-ui/src/services/dropdown-manager.service.ts
+++ b/packages/sheets-data-validation-ui/src/services/dropdown-manager.service.ts
@@ -18,7 +18,6 @@ import type { CellValue, DateKit, IDisposable, IExcelDateTimeParts, Nullable, Wo
import type { ISetRangeValuesCommandParams, ISheetLocation } from '@univerjs/sheets';
import type { ListValidator } from '@univerjs/sheets-data-validation';
import type { IDropdownParam, IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui';
-import type { IUniverSheetsDataValidationUIConfig } from '../config/config';
import { CellValueType, DataValidationErrorStyle, DataValidationRenderMode, dateKit, DateSystem, Disposable, DisposableCollection, excelDateTimePartsToSerial, excelSerialToDateTimeParts, ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, numfmt, UniverInstanceType } from '@univerjs/core';
import { DataValidatorDropdownType, DataValidatorRegistryService } from '@univerjs/data-validation';
import { DeviceInputEventType } from '@univerjs/engine-render';
@@ -28,6 +27,7 @@ import { getPatternType } from '@univerjs/sheets-numfmt';
import { IEditorBridgeService, ISheetCellDropdownManagerService, SetCellEditVisibleOperation } from '@univerjs/sheets-ui';
import { KeyCode } from '@univerjs/ui';
import { Subject } from 'rxjs';
+import type { IUniverSheetsDataValidationUIConfig } from '../config/config';
import { OpenValidationPanelOperation } from '../commands/operations/data-validation.operation';
import { SHEETS_DATA_VALIDATION_UI_PLUGIN_CONFIG_KEY } from '../config/config';
import { DROP_DOWN_DEFAULT_COLOR } from '../const';
@@ -157,7 +157,15 @@ export class DataValidationDropdownManagerService extends Disposable {
return;
}
- const rule = this._dataValidationModel.getRuleByLocation(workbook.getUnitId(), worksheet.getSheetId(), row, col);
+ // A merged cell keeps its validation rule on the merge main cell, while a selection that
+ // lands on a covered cell reports that covered cell as the primary one.
+ const mergeCell = worksheet.getMergedCell(row, col);
+ const rule = this._dataValidationModel.getRuleByLocation(
+ workbook.getUnitId(),
+ worksheet.getSheetId(),
+ mergeCell?.startRow ?? row,
+ mergeCell?.startColumn ?? col
+ );
if (!rule) {
return;
}