Skip to content

Commit

Permalink
fix(TextInput/isFocused): correctly handle null focused input (#13219)
Browse files Browse the repository at this point in the history
* Change files

* fix(TextInput/isFocused): correctly handle null focused input

Signed-off-by: Nathanael Bracy <nate@bracy.dev>

* fix

---------

Signed-off-by: Nathanael Bracy <nate@bracy.dev>
Co-authored-by: Andrew Coates <30809111+acoates-ms@users.noreply.github.com>
  • Loading branch information
servusdei2018 and acoates-ms authored May 13, 2024
1 parent 8f366c5 commit e2a0c87
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1278,9 +1278,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<HostComponent<mixed>> {
return inputRef.current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1310,9 +1310,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<HostComponent<mixed>> {
return inputRef.current;
Expand Down

0 comments on commit e2a0c87

Please sign in to comment.