diff --git a/change/react-native-windows-3adee0f5-93e2-4451-bc8a-967121f90520.json b/change/react-native-windows-3adee0f5-93e2-4451-bc8a-967121f90520.json new file mode 100644 index 00000000000..caf3f75e930 --- /dev/null +++ b/change/react-native-windows-3adee0f5-93e2-4451-bc8a-967121f90520.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Fix bug when blur command received on node without XamlRoot", + "packageName": "react-native-windows", + "email": "erozell@outlook.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Modules/NativeUIManager.cpp b/vnext/Microsoft.ReactNative/Modules/NativeUIManager.cpp index 8b911866745..8da4aa1dea5 100644 --- a/vnext/Microsoft.ReactNative/Modules/NativeUIManager.cpp +++ b/vnext/Microsoft.ReactNative/Modules/NativeUIManager.cpp @@ -1171,7 +1171,9 @@ void NativeUIManager::blur(int64_t reactTag) { if (auto shadowNode = static_cast(m_host->FindShadowNodeForTag(reactTag))) { // Only blur if current UI is focused to avoid problem described in PR #2687 const auto xamlRoot = tryGetXamlRoot(shadowNode->m_rootTag); - if (shadowNode->GetView() == xaml::Input::FocusManager::GetFocusedElement(xamlRoot)) { + const auto focusedElement = xamlRoot ? xaml::Input::FocusManager::GetFocusedElement(xamlRoot) + : xaml::Input::FocusManager::GetFocusedElement(); + if (shadowNode->GetView() == focusedElement) { if (auto reactControl = GetParentXamlReactControl(reactTag).get()) { reactControl.as()->blur(shadowNode->GetView()); } else {