diff --git a/change/react-native-windows-a8b5bad4-4783-4c5f-a6f4-c227c9b6c8d9.json b/change/react-native-windows-a8b5bad4-4783-4c5f-a6f4-c227c9b6c8d9.json new file mode 100644 index 00000000000..01eb4e990fc --- /dev/null +++ b/change/react-native-windows-a8b5bad4-4783-4c5f-a6f4-c227c9b6c8d9.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "add accessibility UIA headings", + "packageName": "react-native-windows", + "email": "agnel@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Views/TextViewManager.cpp b/vnext/Microsoft.ReactNative/Views/TextViewManager.cpp index e49b8860e3c..e8ae7c581e9 100644 --- a/vnext/Microsoft.ReactNative/Views/TextViewManager.cpp +++ b/vnext/Microsoft.ReactNative/Views/TextViewManager.cpp @@ -288,6 +288,23 @@ bool TextViewManager::UpdateProperty( node->m_backgroundColor = OptionalColorFrom(propertyValue); node->RecalculateTextHighlighters(); } + } else if (propertyName == "accessibilityRole") { + if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::String) { + const std::string &role = propertyValue.AsString(); + auto value = asHstring(propertyValue); + auto boxedValue = winrt::Windows::Foundation::PropertyValue::CreateString(value); + + textBlock.SetValue(winrt::AutomationProperties::LocalizedControlTypeProperty(), boxedValue); + if (role == "header") { + xaml::Automation::AutomationProperties::SetHeadingLevel( + textBlock, winrt::Peers::AutomationHeadingLevel::Level2); + } else { + textBlock.ClearValue(winrt::AutomationProperties::HeadingLevelProperty()); + } + } else if (propertyValue.IsNull()) { + textBlock.ClearValue(winrt::AutomationProperties::LocalizedControlTypeProperty()); + textBlock.ClearValue(winrt::AutomationProperties::HeadingLevelProperty()); + } } else { return Super::UpdateProperty(nodeToUpdate, propertyName, propertyValue); }