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;