Skip to content

Conversation

@amanmahajan7
Copy link
Collaborator

@amanmahajan7 amanmahajan7 commented Dec 9, 2024

  • Added onCellCopy and onCellPaste props
  • Grid now uses native onCopy and onPaste events
  • Copy state has been removed as it can be implemented outside the grid.

Fixes
#2736
#1950

@amanmahajan7 amanmahajan7 self-assigned this Dec 9, 2024
@s-elmer
Copy link

s-elmer commented Mar 19, 2025

Hi are there currently plans to add this feature? It would be very appreciated for my use case

@codecov
Copy link

codecov bot commented Mar 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.80%. Comparing base (3a53387) to head (d7cb222).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3667      +/-   ##
==========================================
+ Coverage   98.75%   98.80%   +0.05%     
==========================================
  Files          47       47              
  Lines        3447     3424      -23     
  Branches      750      743       -7     
==========================================
- Hits         3404     3383      -21     
+ Misses         43       41       -2     
Files with missing lines Coverage Δ
src/Cell.tsx 100.00% <ø> (ø)
src/DataGrid.tsx 99.77% <100.00%> (-0.01%) ⬇️
src/Row.tsx 100.00% <ø> (ø)
src/TreeDataGrid.tsx 95.95% <100.00%> (+0.75%) ⬆️
src/index.ts 100.00% <ø> (ø)
src/types.ts 100.00% <ø> (ø)
src/utils/keyboardUtils.ts 96.82% <100.00%> (+0.15%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

src/index.ts Outdated
FillEvent,
CopyEvent,
PasteEvent,
CellCopyPasteEvent,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add two separate events (CellCopyEvent and CellPasteEvent)?

Copy link
Collaborator

@nstepien nstepien Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can do

type CellCopyEvent = CellCopyPasteEvent;
type CellPasteEvent = CellCopyPasteEvent;

and export those instead, it'll be safer to extend one or the other in the future.

}}
/>
<>
{copiedCell && (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there is is another way to set copied cell styles

@amanmahajan7 amanmahajan7 marked this pull request as ready for review April 3, 2025 17:13
@amanmahajan7 amanmahajan7 requested a review from nstepien as a code owner April 3, 2025 17:13
Copy link
Collaborator

@nstepien nstepien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if I copy something outside the grid then pastes it onto a cell?

src/index.ts Outdated
FillEvent,
CopyEvent,
PasteEvent,
CellCopyPasteEvent,
Copy link
Collaborator

@nstepien nstepien Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can do

type CellCopyEvent = CellCopyPasteEvent;
type CellPasteEvent = CellCopyPasteEvent;

and export those instead, it'll be safer to extend one or the other in the future.

@amanmahajan7
Copy link
Collaborator Author

What happens if I copy something outside the grid then pastes it onto a cell?

Users can decide how to handle it. In the example, I am updating the cell
https://github.com/adazzle/react-data-grid/blob/2fdd7389ad49e00f3a91eb02f93ccf6533a08e2c/website/routes/AllFeatures.tsx#L242

@amanmahajan7 amanmahajan7 merged commit ba6c8ea into main Apr 10, 2025
2 checks passed
@amanmahajan7 amanmahajan7 deleted the am-native-copy-paste branch April 10, 2025 18:55
@GersonDias
Copy link

just to advise future readers, this is a breaking changing. Would be nice to have some docs related to this, but basically now you need to handle the copy event and save what you need in a state to use it when you need. No more sourceRow in the paste event. Would be nice if this was opt-in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants