feat(grid): link cell detail to selection

This commit is contained in:
t8y2
2026-05-22 01:41:30 +08:00
parent af5eb9cb2f
commit 612c6d36db
3 changed files with 55 additions and 0 deletions
@@ -4,6 +4,7 @@ import {
canFormatCellDetailJson,
cellDetailEditorText,
defaultCellDetailTab,
linkedCellDetailTarget,
visibleCellDetailTabs,
valueEditorActions,
type CellDetailPresentationOptions,
@@ -54,3 +55,24 @@ test("cell detail value editor uses cell actions instead of confirm and cancel",
]);
assert.deepEqual(valueEditorActions({ canSetNull: false }), ["restoreOriginal"]);
});
test("cell detail follows the selected grid cell while open", () => {
assert.deepEqual(
linkedCellDetailTarget({
isOpen: true,
isEditing: false,
selectedCell: { rowIndex: 2, visibleColIndex: 1 },
actualColumnIndex: (visibleColIndex) => [0, 3, 5][visibleColIndex] ?? visibleColIndex,
}),
{ rowIndex: 2, col: 3 },
);
});
test("cell detail does not follow selection while closed or editing", () => {
const selectedCell = { rowIndex: 2, visibleColIndex: 1 };
const actualColumnIndex = (visibleColIndex: number) => visibleColIndex;
assert.equal(linkedCellDetailTarget({ isOpen: false, isEditing: false, selectedCell, actualColumnIndex }), null);
assert.equal(linkedCellDetailTarget({ isOpen: true, isEditing: true, selectedCell, actualColumnIndex }), null);
assert.equal(linkedCellDetailTarget({ isOpen: true, isEditing: false, selectedCell: null, actualColumnIndex }), null);
});