diff --git a/change/react-native-windows-29f65fa8-43ca-4485-9da4-0168ac84cd17.json b/change/react-native-windows-29f65fa8-43ca-4485-9da4-0168ac84cd17.json new file mode 100644 index 00000000000..87a580ff0c8 --- /dev/null +++ b/change/react-native-windows-29f65fa8-43ca-4485-9da4-0168ac84cd17.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Fix announceForAccessibility", + "packageName": "react-native-windows", + "email": "34109996+chiaramooney@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp b/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp index a09dfe49deb..ee4e68f5674 100644 --- a/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp @@ -41,27 +41,16 @@ void AccessibilityInfo::setAccessibilityFocus(double /*reactTag*/) noexcept { void AccessibilityInfo::announceForAccessibility(std::string announcement) noexcept { m_context.UIDispatcher().Post([context = m_context, announcement = std::move(announcement)] { - xaml::UIElement element{nullptr}; + // Windows requires a specific element to announce from. Unfortunately the react-native API does not provide a tag + // So we need to add a temporary control to raise the notification event from. - // Windows requires a specific element to announce from. Unfortunately the react-native API does not provide a tag - // So we need to find something to try to raise the notification event from + auto textBlock = xaml::Controls::TextBlock(); - if (auto window = xaml::Window::Current()) { - element = window.Content(); - } - - if (!element && react::uwp::Is19H1OrHigher()) { - // XamlRoot added in 19H1 - if (auto xamlRoot = React::XamlUIService::GetXamlRoot(context.Properties().Handle())) { - element = xamlRoot.Content(); - } - } - - if (!element) { + if (!textBlock) { return; } - auto peer = xaml::Automation::Peers::FrameworkElementAutomationPeer::FromElement(element); + auto peer = xaml::Automation::Peers::FrameworkElementAutomationPeer::FromElement(textBlock); if (!peer) { return;