Skip to content

Commit 0d13a12

Browse files
Expose unselectCell on DataGrid handle
1 parent 17d564b commit 0d13a12

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/DataGrid.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export interface DataGridHandle {
111111
element: HTMLDivElement | null;
112112
scrollToCell: (position: PartialPosition) => void;
113113
selectCell: (position: Position, options?: SelectCellOptions) => void;
114+
unselectCell: () => void;
114115
}
115116

116117
type SharedDivProps = Pick<
@@ -547,7 +548,8 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
547548
setScrollToPosition({ idx: scrollToIdx, rowIdx: scrollToRowIdx });
548549
}
549550
},
550-
selectCell
551+
selectCell,
552+
unselectCell
551553
})
552554
);
553555

@@ -859,6 +861,13 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
859861
}
860862
}
861863

864+
function unselectCell(): void {
865+
commitEditorChanges();
866+
867+
setShouldFocusCell(false);
868+
setSelectedPosition({ idx: -1, rowIdx: minRowIdx - 1, mode: 'SELECT' });
869+
}
870+
862871
function selectHeaderCell({ idx, rowIdx }: Position): void {
863872
selectCell({ rowIdx: minRowIdx + rowIdx - 1, idx });
864873
}
@@ -1368,3 +1377,4 @@ function getCellToScroll(gridEl: HTMLDivElement) {
13681377
function isSamePosition(p1: Position, p2: Position) {
13691378
return p1.idx === p2.idx && p1.rowIdx === p2.rowIdx;
13701379
}
1380+

0 commit comments

Comments
 (0)