microsoft / microsoft/react-native-windows

Proposal: TextInput onPaste event

Open
#7,574 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement Needs: Dev Design Partner: Facebook Upstream Workstream: Component Parity
Dominant language
C++
Stars
17.3k
Forks
1.2k
Avg merge
1d 13h
Merged PRs (30d)
33

Description

Proposal: TextInput onPaste event

In order to support pasting things like images or attachments into a TextBox, we need an event to notify React Native that something has been pasted.

Summary

A set of props to configure which clipboard formats should be handled by React Native JS when pasted into a TextInput and a corresponding event that fires when these formats are pasted.

Motivation

In order to support scenarios that allow for pasting attachments / images / rich text / etc. into React Native's TextInput, we may need to subscribe to the TextBox.Paste event.

This has been proposed in the past in React Native core, but was perceived as too risky without a thorough investigation of how this might be implemented outside of core:
https://github.com/facebook/react-native/pull/22794

I don't believe any such options exist, though we have proposed the concept of "view manager extensions" in the past:
https://github.com/microsoft/react-native-windows/pull/1618

Another alternative might be to implement keyDownEvents for Ctrl+V and override the native context menu for TextInput (to create your own menu item that wires up to the Clipboard module). However, if your scenario is to only override paste behaviors for files and images, then you'll also need to re-implement the native paste behaviors for text, rich text, HTML, URIs, etc.

Basic example

const handledPasteFormats = [ 'StorageItem', 'Bitmap' ];
const onPaste = () => {
  if (ClipboardModule.contains('StorageItem')) {
    // File attachment handling
  } else if (ClipboardModule.contains('Bitmap')) {
    // Image attachment handling
  }
};

...

<TextInput
  handledPasteFormats={handledPasteFormats}
  onPaste={onPaste} />

Open Questions

If we're implementing RN overrides for Paste, do we also want to expand this to copy and cut as well via the TextBox.CopyingToClipboard and TextBox.CuttingToClipboard events?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed TextInput props and onPaste event, then read the referenced React Native pull request and React Native Windows view manager extensions proposal. Investigate the native TextBox.Paste event and the open questions about copy and cut; done would require a settled API and implementation scope rather than only a proposal.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native
Domain
desktop-dev, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.