Skip to content

Use native copy/paste event handlers #3667

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 19 commits into from
Apr 10, 2025
Merged

Use native copy/paste event handlers #3667

merged 19 commits into from
Apr 10, 2025

Conversation

amanmahajan7
Copy link
Contributor

@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

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
@@ -34,8 +34,7 @@ export type {
SelectHeaderRowEvent,
SelectRowEvent,
FillEvent,
CopyEvent,
PasteEvent,
CellCopyPasteEvent,
Copy link
Contributor 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
Contributor

@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
Contributor 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
Contributor

@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
@@ -34,8 +34,7 @@ export type {
SelectHeaderRowEvent,
SelectRowEvent,
FillEvent,
CopyEvent,
PasteEvent,
CellCopyPasteEvent,
Copy link
Contributor

@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
Contributor 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

const copiedText = event.clipboardData.getData('text/plain');

@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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants