From e92222446f36a0ec446900fc1b5570c9c6adbd30 Mon Sep 17 00:00:00 2001 From: QichenZhu <57348009+QichenZhu@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:04:04 +1200 Subject: [PATCH] [fix] TextInput refocusing issue with selectTextOnFocus Check if the input is still focused before selecting text Fix #2704 --- packages/react-native-web/src/exports/TextInput/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/react-native-web/src/exports/TextInput/index.js b/packages/react-native-web/src/exports/TextInput/index.js index 83f89af33..03649c394 100644 --- a/packages/react-native-web/src/exports/TextInput/index.js +++ b/packages/react-native-web/src/exports/TextInput/index.js @@ -290,7 +290,9 @@ const TextInput: React.AbstractComponent< clearTimeout(focusTimeout); } focusTimeout = setTimeout(() => { - if (hostNode != null) { + // Check if the input is still focused after the timeout + // (see #2704) + if (hostNode != null && document.activeElement === hostNode) { hostNode.select(); } }, 0);