diff --git a/.unbroken_exclusions b/.unbroken_exclusions index c45218154c0..fc3b366a363 100644 --- a/.unbroken_exclusions +++ b/.unbroken_exclusions @@ -21,3 +21,4 @@ URL not found https://docs.github.com/get-started/quickstart while parsing CONTR !packages/@rnw-scripts/format-files/node_modules !packages/@rnw-scripts/promote-release/node_modules !.github/ISSUE_TEMPLATE +!.github/security.md \ No newline at end of file diff --git a/change/@office-iss-react-native-win32-25963317-e0eb-4d0b-8253-3e2490f2a1ab.json b/change/@office-iss-react-native-win32-25963317-e0eb-4d0b-8253-3e2490f2a1ab.json new file mode 100644 index 00000000000..be71cff759a --- /dev/null +++ b/change/@office-iss-react-native-win32-25963317-e0eb-4d0b-8253-3e2490f2a1ab.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "[Win32] view.focus sometimes skips setting focus", + "packageName": "@office-iss/react-native-win32", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js b/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js index 73e68522f2d..79373c4b650 100644 --- a/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js +++ b/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js @@ -21,8 +21,7 @@ import type { import {Commands as AndroidTextInputCommands} from '../../Components/TextInput/AndroidTextInputNativeComponent'; import {Commands as iOSTextInputCommands} from '../../Components/TextInput/RCTSingelineTextInputNativeComponent'; - -import {UIManager} from 'react-native'; +import {Commands as Win32TextInputCommands} from '../../Components/TextInput/Win32TextInputNativeComponent'; const {findNodeHandle} = require('../../ReactNative/RendererProxy'); const Platform = require('../../Utilities/Platform'); @@ -106,7 +105,16 @@ function focusTextInput(textField: ?ComponentRef) { return; } - if (textField != null) { + // [Win32 + if (Platform.OS === 'win32' && textField != null) { + // On Windows, we cannot test if the currentlyFocusedInputRef equals the + // target ref because the call to focus on the target ref may occur before + // an onBlur event for the target ref has been dispatched to JS but after + // the target ref has lost native focus. + focusInput(textField); + Win32TextInputCommands.focus(textField); + // Win32] + } else if (textField != null) { const fieldCanBeFocused = currentlyFocusedInputRef !== textField && // $FlowFixMe - `currentProps` is missing in `NativeMethods` @@ -126,11 +134,6 @@ function focusTextInput(textField: ?ComponentRef) { } else if (Platform.OS === 'android') { AndroidTextInputCommands.focus(textField); } - // [Win32 - else if (Platform.OS === 'win32') { - UIManager.focus(findNodeHandle(textField)); - } - // Win32] } } @@ -164,7 +167,7 @@ function blurTextInput(textField: ?ComponentRef) { } // [Win32 else if (Platform.OS === 'win32') { - UIManager.blur(findNodeHandle(textField)); + Win32TextInputCommands.blur(textField); } // Win32] }