Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to focus TextInput on button press in React Native

$
0
0

I have a TextInput component, which is only editable on component mount. It should become editable and auto focused, when a button is pressed. As I understood it correctly, the autoFocus property only works on first mount. Is there any way to implement this on state change?

import { FunctionComponent } from 'react';import { View, TextInput, TextInputProps } from 'react-native';interface InputTextBoxProps {  editingState: boolean;}type InputProps = TextInputProps & InputTextBoxProps;const InputTextBox: FunctionComponent<InputProps> = ({editingState, ...props}) => {  return (<View><TextInput        {...props}        multiline={true}         style={styles.textStyle}        editable={editingState}        autoFocus={editingState}></TextInput></View>  );};

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>