3

Nothing in the docs about this. I want to disable the small popup below when clicking on a TextInput in React Native.

enter image description here

Any ideas ?

4
  • This is iOS only right? I'm pretty sure if you hide your caret the popup also stops showing up. Try setting your textfield's caretHidden prop as true* and check if it works out for you. Commented Oct 17, 2017 at 12:48
  • If possible, I would like the caret to be shown, only the popup to be disabled. Commented Oct 17, 2017 at 14:34
  • I'm looking for this exact issue too. Hopefully we can figure it out! Definitely post the solution if you come across it. Commented Nov 8, 2017 at 22:02
  • 1
    I've currently got a PR out that adds this ability for iOS. Hopefully it can get reviewed/merged soon! github.com/facebook/react-native/pull/16847 Commented Nov 15, 2017 at 22:24

6 Answers 6

10
<TextInput
   contextMenuHidden={true}
   value={this.state.text}
   onChangeText={(text) => this.setState({ text})}
/>
Sign up to request clarification or add additional context in comments.

1 Comment

It does not work. i can still see context menu on double tap
3

for ios

<TextInput contextMenuHidden={true}

for Android

<View removeClippedSubviews={true}>

  <TextInput contextMenuHidden={true} />

</View>

Surender Kumar's answer: React Native 55.4: contextMenuHidden does not hide menu on Android - Disable Options on React-Native Text Input

Comments

2

for stop copy paste the following code is

 <TextInput contextMenuHidden={true}/>

Comments

0

Below solution works for me. I am clearing keyboard on onTouchEnd event

const [text1, setText1] = useState('')
    
const clearClipboard = () =>{
 Clipboard.setString('')
}
    
const onChangeText = (text) =>{
 //For android 12+ clipboard autofill option, dont allow text change more than one char..which means user is typing.
 if(text1.length+1 >= text.length){
  setText1(text)
 }
}
    
<TextInput onChangeText={onChangeText} value={text1} contextMenuHidden={true} onTouchEnd={clearClipboard}></TextInput>

Comments

0

I created custom textview Component for this. To disable the full-screen text input UI that appears when a TextInput component receives focus on Android 13. I have used the The disableFullscreenUI prop. This the only solution that I have found so far which works for all the android versions.

  • For accessing clipboard I have used Clipboard component from eact-native-community/clipboard
  • autoCorrect prop for disabling keyboard suggestions
  • spellCheck prop for disabling keyboard suggestions
  • disableFullscreenUI prop to disable the full-screen text input UI that appears when a TextInput component -Used this custom component where I want to use textView component .

//Code

import React, { useState } from 'react';
import { TextInput as RNTextInput, Platform } from 'react-native';
import Clipboard from '@react-native-community/clipboard';

 const withClipboardRestriction = Component => {
 const WrappedComponent = (props, ref) => {
  const [value, setValue] = useState('');

  const handleChange = text => {
  // Check if the new text is the same as the current text plus one 
   character
  // This means the user has typed a character, not pasted text
  if (
    text === value + text.slice(-1) ||
    text === value.slice(0, -1) ||
    text.length <= value.length
  ) {
    setValue(text);
    if (props.onChangeText) {
      props.onChangeText(text);
     }
       }
        };

            const clearClipboard = () => {
              Clipboard.setString('');
              };

       const newProps = {
       ...props,
       onChangeText: handleChange,
       autoCorrect: false,
       spellCheck: false,
       onTouchEnd: clearClipboard,
       onFocus: clearClipboard,
       undefinedText: '',
       ...(Platform.OS === 'android' && Platform.Version >= 33
         ? { disableFullscreenUI: true }
         : {}),
            };
    
      return <Component {...newProps} ref={ref} contextMenuHidden={true} />;
      };
    
     return React.forwardRef(WrappedComponent);
          };

export const TextInput = withClipboardRestriction(RNTextInput);

 

Comments

0

If you set pointerEvents="none" on a View surrounding the TextInput it will prevent the context menu from displaying:

<View removeClippedSubviews pointerEvents="none">
  <TextInput contextMenuHidden />
</View>

This will work for iOS, Android, and web

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.