-
Notifications
You must be signed in to change notification settings - Fork 80
Description
Bug
When pasting multi-row data via native paste (Ctrl/Cmd+V), if the pasted content has more rows than the table can hold, the extra rows are silently dropped instead of showing the "Do you want to add more rows?" dialog.
Root Cause
In use-data-grid.ts, the onNativePaste handler sets pasteDialog.clipboardText in the store before calling onCellsPaste():
// onNativePaste (line ~2966)
store.setState("pasteDialog", {
...currentState.pasteDialog,
clipboardText: text, // ← stored first
});
onCellsPaste(); // ← then calledInside onCellsPaste, the guard that decides whether to show the expansion dialog checks:
if (
rowsNeeded > 0 &&
!expandRows &&
propsRef.current.onRowAdd &&
!currentState.pasteDialog.clipboardText // ← always false on native paste
) {
store.setState("pasteDialog", { open: true, rowsNeeded, clipboardText });
return;
}Since clipboardText was already written to the store, !currentState.pasteDialog.clipboardText is always false, so the dialog is never shown. The code falls through to the cell-writing loop, which only writes into existing rows and discards the rest.
The !clipboardText check is meant to distinguish a fresh paste (show dialog) from a dialog-confirmed re-entry (clipboardText already in store → proceed). But the native paste path defeats this by pre-populating the store.
Suggested Fix
Pass the clipboard text as an argument to onCellsPaste instead of writing it to the store first:
// onNativePaste — pass text directly
onCellsPaste(false, text);
// onCellsPaste — accept optional override
async (expandRows = false, clipboardTextOverride?: string) => {
// ...
let clipboardText =
clipboardTextOverride ?? currentState.pasteDialog.clipboardText;
// ...
}This way the store's clipboardText remains empty during the first call, the dialog guard works correctly, and the dialog stores clipboardText for the confirmed re-entry as originally intended.
Repro
- Have a data grid with
onRowAddconfigured and fewer rows than clipboard content - Copy multi-row tab-separated data to clipboard
- Focus a cell and press Ctrl/Cmd+V
- Expected: "Do you want to add more rows?" dialog
- Actual: Excess rows silently dropped