Skip to content

Android: a TextInput with its context menu hidden opens no right-click menu - #59136

Open
YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:fix/android-context-menu-hidden-right-click
Open

YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:fix/android-context-menu-hidden-right-click

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

On Android, a mouse right-click on a TextInput with contextMenuHidden still opens the text context menu, with Cut, Copy, Paste, Select all and the other text actions. ReactEditText honours the flag only in its action mode callback, and a right-click starts no action mode: View asks the window for a context menu, and TextView fills it through Editor.onCreateContextMenu.

ReactEditText now adds no items to its context menu while contextMenuHidden is set, and the platform opens no menu without items, whatever asked for it. Editor moves the caret to the clicked position only while it fills that menu, so with the flag a right-click also leaves the caret where it was. A field without the flag keeps its menu. The mouse case was reported in #45355, which was closed as stale.

Changelog:

[ANDROID] [FIXED] - A TextInput with contextMenuHidden no longer opens the context menu on a mouse right-click

Test Plan:

  • New ReactTextInputPropertyTest.testContextMenuHiddenRightClick: with the field attached to an Activity, showContextMenu(x, y), which a right-click calls, opens a menu by default and opens none with contextMenuHidden. On main it fails at the second assertion.

  • RNTester's Playground (RNTesterPlayground.js) with this component:

    Playground
    import * as React from 'react';
    import {StyleSheet, TextInput, View} from 'react-native';
    
    function Playground() {
      return (
        <View style={styles.container}>
          <TextInput
            contextMenuHidden={true}
            defaultValue="Right-click this text"
            style={styles.input}
          />
          <TextInput defaultValue="Right-click this text too" style={styles.input} />
        </View>
      );
    }
    
    const styles = StyleSheet.create({
      container: {
        padding: 10,
      },
      input: {
        borderColor: 'gray',
        borderWidth: 1,
        fontSize: 20,
        marginBottom: 10,
        padding: 10,
      },
    });

    Right-click each field with a mouse. On main both open the context menu and move the caret to the click. With this change the first opens nothing and keeps its caret where it was, whether it is focused or not, and the second still opens its menu and moves its caret. I checked it on RNTester debug builds of main and this branch on an Android 16 phone, with the mouse driven through a uinput virtual device; the captures and readings are in this comment.

  • ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest -PenableWarningsAsErrors=true passes (757 tests), and node ./scripts/format-kotlin.js --check is clean.

…k menu

A mouse right-click on an Android TextInput opens the context menu that
Editor fills with Cut, Copy, Paste, Select all and the other text
actions. ReactEditText honours contextMenuHidden only in its action mode
callback, so a right-click still opened that menu with the flag set.

ReactEditText adds no items to its context menu while contextMenuHidden
is set, and the platform opens no menu without items: not on a
right-click, and not from anything else that asks the view for its
context menu.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 16, 2026
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review October 16, 2026 11:31
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 16, 2026
@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor Author

Device evidence — before / after

UNFIXED — A right-click on the field with contextMenuHidden opens the context menu and moves the caret to the click.

FIXED — It opens nothing and leaves the caret where it was; the field without the flag still opens its menu.

before — main after — with this PR

RedMagic NX809J, Android 16 (API 36): RNTester debug builds of main (e04aaf62f7) and of this PR running the Playground from the description, a second after a right-click on the first field. The builds, the steps and every reading are on this page.

This branch has not been deployed

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant