Skip to content

Native paste silently truncates rows instead of showing expansion dialog #264

@agwax

Description

@agwax

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 called

Inside 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

  1. Have a data grid with onRowAdd configured and fewer rows than clipboard content
  2. Copy multi-row tab-separated data to clipboard
  3. Focus a cell and press Ctrl/Cmd+V
  4. Expected: "Do you want to add more rows?" dialog
  5. Actual: Excess rows silently dropped

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions