Skip to content

Commit 28463c0

Browse files
amanmahajan7nstepien
authored andcommitted
Check whether cell is editable on double click (adazzle#1880)
1 parent 1a43d31 commit 28463c0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/masks/InteractionMasks.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ export default function InteractionMasks<R, K extends keyof R>({
106106
const [firstEditorKeyPress, setFirstEditorKeyPress] = useState<string | null>(null);
107107
const [isEditorEnabled, setIsEditorEnabled] = useState(false);
108108
const selectionMaskRef = useRef<HTMLDivElement>(null);
109-
const isCellEditable = isCellWithinBounds(selectedPosition) && isSelectedCellEditable<R>({ enableCellSelect, columns, rowGetter, selectedPosition, onCheckCellIsEditable });
110109

111110
// Focus on the selection mask when the selected position is changed
112111
useEffect(() => {
@@ -171,7 +170,7 @@ export default function InteractionMasks<R, K extends keyof R>({
171170
}
172171

173172
function openEditor(event: React.KeyboardEvent<HTMLDivElement>): void {
174-
if (isCellEditable && !isEditorEnabled) {
173+
if (!isEditorEnabled && isCellEditable(selectedPosition)) {
175174
setFirstEditorKeyPress(event.key);
176175
setIsEditorEnabled(true);
177176
}
@@ -235,7 +234,7 @@ export default function InteractionMasks<R, K extends keyof R>({
235234
}
236235

237236
function handlePaste(): void {
238-
if (copiedPosition === null || !isCellEditable) {
237+
if (copiedPosition === null || !isCellEditable(selectedPosition)) {
239238
return;
240239
}
241240

@@ -265,6 +264,11 @@ export default function InteractionMasks<R, K extends keyof R>({
265264
return rowIdx >= 0 && rowIdx < rowsCount && idx >= 0 && idx < columns.length;
266265
}
267266

267+
function isCellEditable(position: Position) {
268+
return isCellWithinBounds(position)
269+
&& isSelectedCellEditable<R>({ enableCellSelect, columns, rowGetter, selectedPosition: position, onCheckCellIsEditable });
270+
}
271+
268272
function selectCell(position: Position, enableEditor = false): void {
269273
// Close the editor to commit any pending changes
270274
if (isEditorEnabled) {
@@ -276,15 +280,15 @@ export default function InteractionMasks<R, K extends keyof R>({
276280
scrollToCell(position);
277281
setSelectedPosition(position);
278282
onSelectedCellChange?.({ ...position });
279-
if (enableEditor) {
283+
if (enableEditor && isCellEditable(position)) {
280284
// The editor position is dependent on the selectionMask position so we need to wait
281285
// for the next render cycle when the updated selection mask position is set
282286
setIsEditorEnabled(true);
283287
}
284288
}
285289

286290
function isDragEnabled(): boolean {
287-
return enableCellDragAndDrop && isCellEditable;
291+
return enableCellDragAndDrop && isCellEditable(selectedPosition);
288292
}
289293

290294
function handleDragStart(e: React.DragEvent<HTMLDivElement>): void {

0 commit comments

Comments
 (0)