Positioning cursor in TextInput

Please provide the following:

  1. SDK Version: 47.0.0
  2. Platforms(Android/iOS/web/all): all

I have a TextInput with textAlign: "right", and when I focus on it, I want it to switch to textAlign: "left" and also I want to position the cursor at the end of the text.

I am unable to do so.

const [style, setStyle] = useState({ textAlign: "right" });
const inputRef = useRef();

const handleFocus = () => {
    setStyle({ textAlign: "left" });
    inputRef.current.selection = {
      start: inputRef.current.value.length - 1,
      end: inputRef.current.value.length - 1,
    };
}

  const handleBlur = () => {
    setStyle({ textAlign: "right" });
  };

<TextInput ref={inputRef} style={style} onFocus={handleFocus} onBlur={handleBlur} />

Sample: TextInput Example - Snack

Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.