mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
4.12k stars 1.27k forks source link

[data grid] Can paste cell content into non-editable cells #11984

Open ikzhr opened 7 months ago

ikzhr commented 7 months ago

Steps to reproduce

Link to live example: https://codesandbox.io/p/devbox/pm4zm7?file=%2Fsrc%2FDemo.tsx%3A33%2C36&layout=%257B[…]ebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

Notes on example:

Steps:

  1. Visit the live example above
  2. Ctrl+C to copy any cell, Ctrl+V to paste into another cell
  3. The copied contents are copied into another cell

Current behavior

Paste operation can overwrite the contents of non-editable cells.

Expected behavior

Paste operation can NOT overwrite the contents of non-editable cells.

Context

No response

Your environment

npx @mui/envinfo ``` System: OS: macOS 13.3.1 Binaries: Node: 16.15.1 - ~/.anyenv/envs/nodenv/versions/16.15.1/bin/node npm: 8.11.0 - ~/.anyenv/envs/nodenv/versions/16.15.1/bin/npm pnpm: Not Found Browsers: Chrome: 121.0.6167.139 ⭐ My default browser Edge: 121.0.2277.106 Safari: 16.4 ```

Search keywords: DataGridPremium paste non-editable Order ID: 74090

ikzhr commented 7 months ago

I think I understand the cause and how to fix it, so if it is considered a bug, I will create a PR to fix it.

The cause is that the update process (updateCell) during paste only refers to the editable property of the column.

apiRef.current.getCellParams(rowId, field).isEditable takes into account both the column settings and the control of the isCellEditable prop, so I think this property should be used to determine if an update should be applied.

michelengelen commented 7 months ago

Hey @ikzhr ... thanks for raising this issue. IMHO this should be considered a bug, but would like to ask @joserodolfofreitas for his opinion!

cherniavskii commented 7 months ago

I confirm it's a bug - clipboard paste doesn't use the isCellEditable prop while it should.

@ikzhr If you're willing to open a PR - instead of using getCellParams().isEditable you can call isCellEditable directly. This will be faster, because getCellParams also calls valueFormatter that we don't need for the clipboard paste.

ikzhr commented 7 months ago

@cherniavskii @michelengelen Thanks, I'll try to fix it.