[fix] Avoid edge case where focus jumps between TextInputs

Close #2163
Fix #2162
This commit is contained in:
Markus Kobisch
2022-02-17 14:47:36 -08:00
committed by Nicolas Gallagher
parent 438b7b7281
commit d21c401620
+9 -2
View File
@@ -83,6 +83,8 @@ function isEventComposing(nativeEvent) {
return nativeEvent.isComposing || nativeEvent.keyCode === 229;
}
let focusTimeout: ?TimeoutID = null;
const TextInput: React.AbstractComponent<
TextInputProps,
HTMLElement & PlatformMethods
@@ -243,8 +245,13 @@ const TextInput: React.AbstractComponent<
}
if (selectTextOnFocus) {
// Safari requires selection to occur in a setTimeout
setTimeout(() => {
hostNode.select();
if (focusTimeout != null) {
clearTimeout(focusTimeout);
}
focusTimeout = setTimeout(() => {
if (hostNode != null) {
hostNode.select();
}
}, 0);
}
}