Skip to content

Android: a TextInput with its context menu hidden takes no long press - #59130

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

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

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

On Android, a TextInput with contextMenuHidden still runs the long press that exists to open that menu. Holding a word selects it and focuses the field without opening the keyboard, and the menu never appears. Holding and sliding off the field before lifting leaves it focused too. The flag refused the long press until #45014, which replaced the long-click listener that consumed it with the action mode callback, and that callback runs only after Editor has selected the word.

ReactEditText is no longer long-clickable while contextMenuHidden is set, so View never starts the long press and accessibility stops offering one. A held press then ends like a tap: lifted on the field, it places the caret and opens the keyboard; lifted elsewhere, it does nothing. TextView turns long-clicking back on when it sets a key listener, which every keyboard type change does, and when onAttachedToWindow makes the text selectable, so the gate is in setLongClickable.

Changelog:

[ANDROID] [FIXED] - A TextInput with contextMenuHidden no longer selects a word and takes focus on a long press

Test Plan:

  • New ReactTextInputPropertyTest.testContextMenuHidden: the field is long-clickable by default; with contextMenuHidden it is not, and stays that way after setting the flag again, a keyboard type change, and setTextIsSelectable(true) (what onAttachedToWindow calls); clearing the flag makes it long-clickable again. On main it fails at the second assertion.

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

    Playground
    import RNTesterText from '../../components/RNTesterText';
    import * as React from 'react';
    import {StyleSheet, TextInput, View} from 'react-native';
    
    function Playground() {
      const [focused, setFocused] = React.useState(false);
      const [selection, setSelection] = React.useState({end: 0, start: 0});
      return (
        <View style={styles.container}>
          <TextInput
            contextMenuHidden={true}
            defaultValue="Press and hold a word"
            onBlur={() => setFocused(false)}
            onFocus={() => setFocused(true)}
            onSelectionChange={event => setSelection(event.nativeEvent.selection)}
            style={styles.input}
          />
          <RNTesterText>
            {`${focused ? 'focused' : 'not focused'}, selection ${selection.start}-${selection.end}`}
          </RNTesterText>
        </View>
      );
    }
    
    const styles = StyleSheet.create({
      container: {
        padding: 10,
      },
      input: {
        borderColor: 'gray',
        borderWidth: 1,
        fontSize: 20,
        marginBottom: 10,
        padding: 10,
      },
    });

    Press and hold the word "hold" for a second, then lift. On main the word is selected and the field focused while it is held, and the keyboard stays down after the release: on Android 14 and 16 the caret moves to the end of the word, and on Android 10 the word stays selected. With this change nothing happens while it is held, and the release places the caret where the finger lifts and opens the keyboard. Press and hold, then slide off the field and lift: on main the field ends up focused, and with this change it stays unfocused. I checked it on RNTester debug builds of main and this branch on Android 10, 14 and 16 phones, with the same result on every round.

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

A long press on an Android TextInput selects the word under the finger
and focuses the field so the text action menu can act on the selection.
With contextMenuHidden set the menu never opens, so the long press only
selected a word nothing could act on and focused the field with the
keyboard down.

ReactEditText is not long-clickable while contextMenuHidden is set:
View never starts the long press, accessibility no longer offers one,
and a press held on the field ends as a click when it lifts on it.
TextView turns long-clicking back on when setInputType sets a key
listener and when onAttachedToWindow makes the text selectable, so the
gate sits in setLongClickable.
@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 10:12
@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

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