@@ -106,7 +106,6 @@ export default function InteractionMasks<R, K extends keyof R>({
106
106
const [ firstEditorKeyPress , setFirstEditorKeyPress ] = useState < string | null > ( null ) ;
107
107
const [ isEditorEnabled , setIsEditorEnabled ] = useState ( false ) ;
108
108
const selectionMaskRef = useRef < HTMLDivElement > ( null ) ;
109
- const isCellEditable = isCellWithinBounds ( selectedPosition ) && isSelectedCellEditable < R > ( { enableCellSelect, columns, rowGetter, selectedPosition, onCheckCellIsEditable } ) ;
110
109
111
110
// Focus on the selection mask when the selected position is changed
112
111
useEffect ( ( ) => {
@@ -171,7 +170,7 @@ export default function InteractionMasks<R, K extends keyof R>({
171
170
}
172
171
173
172
function openEditor ( event : React . KeyboardEvent < HTMLDivElement > ) : void {
174
- if ( isCellEditable && ! isEditorEnabled ) {
173
+ if ( ! isEditorEnabled && isCellEditable ( selectedPosition ) ) {
175
174
setFirstEditorKeyPress ( event . key ) ;
176
175
setIsEditorEnabled ( true ) ;
177
176
}
@@ -235,7 +234,7 @@ export default function InteractionMasks<R, K extends keyof R>({
235
234
}
236
235
237
236
function handlePaste ( ) : void {
238
- if ( copiedPosition === null || ! isCellEditable ) {
237
+ if ( copiedPosition === null || ! isCellEditable ( selectedPosition ) ) {
239
238
return ;
240
239
}
241
240
@@ -265,6 +264,11 @@ export default function InteractionMasks<R, K extends keyof R>({
265
264
return rowIdx >= 0 && rowIdx < rowsCount && idx >= 0 && idx < columns . length ;
266
265
}
267
266
267
+ function isCellEditable ( position : Position ) {
268
+ return isCellWithinBounds ( position )
269
+ && isSelectedCellEditable < R > ( { enableCellSelect, columns, rowGetter, selectedPosition : position , onCheckCellIsEditable } ) ;
270
+ }
271
+
268
272
function selectCell ( position : Position , enableEditor = false ) : void {
269
273
// Close the editor to commit any pending changes
270
274
if ( isEditorEnabled ) {
@@ -276,15 +280,15 @@ export default function InteractionMasks<R, K extends keyof R>({
276
280
scrollToCell ( position ) ;
277
281
setSelectedPosition ( position ) ;
278
282
onSelectedCellChange ?.( { ...position } ) ;
279
- if ( enableEditor ) {
283
+ if ( enableEditor && isCellEditable ( position ) ) {
280
284
// The editor position is dependent on the selectionMask position so we need to wait
281
285
// for the next render cycle when the updated selection mask position is set
282
286
setIsEditorEnabled ( true ) ;
283
287
}
284
288
}
285
289
286
290
function isDragEnabled ( ) : boolean {
287
- return enableCellDragAndDrop && isCellEditable ;
291
+ return enableCellDragAndDrop && isCellEditable ( selectedPosition ) ;
288
292
}
289
293
290
294
function handleDragStart ( e : React . DragEvent < HTMLDivElement > ) : void {
0 commit comments