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

Focus TextInput after select

$
0
0

I got an error when I tried to focus a TextInput after selecting a Dropdown value.And also, when I tried to write, it's lost focus, but I think it is related to how I'm trying to do this.

This is the function that I use to set the inputRef

  let inputRef = useRef<TextInput | null>(null)  const onSelectFormat = (format) => {    setDropdownListVisibility('')    setInputFocused(true)    inputRef.current &&  inputRef.current.focus()  }

The CustomInput Component that I send the inputRef variable

<CustomInput        value={value}        onChangeText={onChangeInputText}        isFocused={isInputFocused}        onFocus={() => setInputFocused(true)}        getRef={ref => (inputRef = { current: ref })}      />

And finally, this is the child component that I pass the ref.

<TextInput          ref={getRef}          value={value}          onChangeText={onChangeText}          style={styles.input}          onFocus={onFocus}        />

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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