Skip to content

Conversation

@naoki-tateyama
Copy link

@naoki-tateyama naoki-tateyama commented Feb 24, 2024

Hi, maintainers!
This PR implements onCopy/onPaste events as Cell Clipboard Events not parts of keydown events.

Previously, copy and paste events were implemented as part of keydown events.
This could be slightly confusing for developers. For example, preventGridDefault method cannot be used to prevent the default onCopy behavior.
With this PR, developers can now utilize Clipboard events, allowing for development with natural APIs without the need to use navigator.clipboard.writeText.

Additionally, by separating the processes that were aggregated under keydown events into onCopy and onPaste events, it is possible to reduce the complexity of the implementation.

I believe this feature is in high demand among many developers.
I hope you will consider it.

Related PRs

Related issues


###### `onCopy?: Maybe<(args: CellCopyArgs<R>, event: CellClipboardEvent) => void>`

###### `onPaste?: Maybe<(args: CellPasteArgs<R>, event: CellClipboardEvent) => R>`
Copy link
Author

@naoki-tateyama naoki-tateyama Feb 24, 2024

Choose a reason for hiding this comment

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

There are two things to consider.

  • It might be more appropriate to name each handler onCellCopy/onCellPaste
  • onPaste might not need to return R.

However, above changes will be breaking changes for some developers.
I leave them as they are without making any changes for now.

Comment on lines +637 to 639
if (cellEvent.isGridDefaultPrevented()) return;

updateRow(targetColumn, rowIdx, updatedTargetRow);
Copy link
Author

Choose a reason for hiding this comment

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

if developers use event.preventGridDefault() in onPaste handler, the default behavior to update the row would be prevented.

Comment on lines +607 to 609
if (cellEvent.isGridDefaultPrevented()) return;

setCopiedCell({ row: sourceRow, columnKey: sourceColumnKey });
Copy link
Author

Choose a reason for hiding this comment

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

if developers use event.preventGridDefault() in onCopy handler, the default behavior to set the copied cell internally would be prevented.

@s-elmer
Copy link

s-elmer commented Mar 14, 2025

Would love to see this feature added!

@amanmahajan7
Copy link
Collaborator

Thank you for the PR.
Copy/Paste support added in #3667

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.

3 participants