From fc6f5fa2f1b96e0492cb0778a3a36bfaf10e9d08 Mon Sep 17 00:00:00 2001 From: Nate <37554478+servusdei2018@users.noreply.github.com> Date: Mon, 13 May 2024 14:50:32 -0400 Subject: [PATCH] fix(TextInput/isFocused): correctly handle null focused input (#13219) * Change files * fix(TextInput/isFocused): correctly handle null focused input Signed-off-by: Nathanael Bracy * fix --------- Signed-off-by: Nathanael Bracy Co-authored-by: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> --- ...-native-win32-153ff284-0e4b-42da-8d03-d6585a865cf4.json | 7 +++++++ ...ative-windows-f51acce3-f93a-49cb-955a-38ff1bef4726.json | 7 +++++++ package.json | 5 +++-- .../Libraries/Components/TextInput/TextInput.win32.js | 4 ++-- .../Libraries/Components/TextInput/TextInput.windows.js | 4 ++-- 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 change/@office-iss-react-native-win32-153ff284-0e4b-42da-8d03-d6585a865cf4.json create mode 100644 change/react-native-windows-f51acce3-f93a-49cb-955a-38ff1bef4726.json diff --git a/change/@office-iss-react-native-win32-153ff284-0e4b-42da-8d03-d6585a865cf4.json b/change/@office-iss-react-native-win32-153ff284-0e4b-42da-8d03-d6585a865cf4.json new file mode 100644 index 00000000000..0a1543285cb --- /dev/null +++ b/change/@office-iss-react-native-win32-153ff284-0e4b-42da-8d03-d6585a865cf4.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "fix(TextInput/isFocused): correctly handle null focused input", + "packageName": "@office-iss/react-native-win32", + "email": "nate@bracy.dev", + "dependentChangeType": "none" +} diff --git a/change/react-native-windows-f51acce3-f93a-49cb-955a-38ff1bef4726.json b/change/react-native-windows-f51acce3-f93a-49cb-955a-38ff1bef4726.json new file mode 100644 index 00000000000..04576436d3e --- /dev/null +++ b/change/react-native-windows-f51acce3-f93a-49cb-955a-38ff1bef4726.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "fix(TextInput/isFocused): correctly handle null focused input", + "packageName": "react-native-windows", + "email": "nate@bracy.dev", + "dependentChangeType": "none" +} diff --git a/package.json b/package.json index 05362eae42b..08f2c966e41 100644 --- a/package.json +++ b/package.json @@ -65,5 +65,6 @@ }, "resolutions.justification": { "z-schema": "CVE-2021-3765 in validator. z-schema is used by rush which is a dependency of lage so should not be executed in this repo" - } -} \ No newline at end of file + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" +} diff --git a/packages/@office-iss/react-native-win32/src-win/Libraries/Components/TextInput/TextInput.win32.js b/packages/@office-iss/react-native-win32/src-win/Libraries/Components/TextInput/TextInput.win32.js index 79d228826c6..067e793e4e2 100644 --- a/packages/@office-iss/react-native-win32/src-win/Libraries/Components/TextInput/TextInput.win32.js +++ b/packages/@office-iss/react-native-win32/src-win/Libraries/Components/TextInput/TextInput.win32.js @@ -1314,9 +1314,9 @@ function InternalTextInput(props: Props): React.Node { ); } }, - // TODO: Fix this returning true on null === null, when no input is focused isFocused(): boolean { - return TextInputState.currentlyFocusedInput() === inputRef.current; + const currentlyFocusedInput = TextInputState.currentlyFocusedInput(); + return currentlyFocusedInput !== null && currentlyFocusedInput === inputRef.current; }, getNativeRef(): ?React.ElementRef> { return inputRef.current; diff --git a/vnext/src-win/Libraries/Components/TextInput/TextInput.windows.js b/vnext/src-win/Libraries/Components/TextInput/TextInput.windows.js index 8ecb2ea5edb..56a470e3a47 100644 --- a/vnext/src-win/Libraries/Components/TextInput/TextInput.windows.js +++ b/vnext/src-win/Libraries/Components/TextInput/TextInput.windows.js @@ -1346,9 +1346,9 @@ function InternalTextInput(props: Props): React.Node { ); } }, - // TODO: Fix this returning true on null === null, when no input is focused isFocused(): boolean { - return TextInputState.currentlyFocusedInput() === inputRef.current; + const currentlyFocusedInput = TextInputState.currentlyFocusedInput(); + return currentlyFocusedInput !== null && currentlyFocusedInput === inputRef.current; }, getNativeRef(): ?React.ElementRef> { return inputRef.current;