Please provide the following:
- SDK Version: 47.0.0
- 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!