diff --git a/change/react-native-windows-4046d3e2-cc00-459e-b62d-4489b3ef14d1.json b/change/react-native-windows-4046d3e2-cc00-459e-b62d-4489b3ef14d1.json new file mode 100644 index 00000000000..d16b5587b17 --- /dev/null +++ b/change/react-native-windows-4046d3e2-cc00-459e-b62d-4489b3ef14d1.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "[Fabric] Fix for Text and TextInput focus issue with screen readers.", + "packageName": "react-native-windows", + "email": "kvineeth@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionTextRangeProvider.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionTextRangeProvider.cpp index 1f69c84b3df..e2260913e15 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionTextRangeProvider.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionTextRangeProvider.cpp @@ -18,14 +18,30 @@ CompositionTextRangeProvider::CompositionTextRangeProvider( } HRESULT __stdcall CompositionTextRangeProvider::Clone(ITextRangeProvider **pRetVal) { - // no-op - *pRetVal = nullptr; + if (pRetVal == nullptr) + return E_POINTER; + + auto clone = winrt::make( + m_view.view().as(), m_parentProvider.get()); + *pRetVal = clone.detach(); return S_OK; } HRESULT __stdcall CompositionTextRangeProvider::Compare(ITextRangeProvider *range, BOOL *pRetVal) { - // no-op - *pRetVal = false; + if (pRetVal == nullptr) + return E_POINTER; + if (range == nullptr) { + *pRetVal = FALSE; + return S_OK; + } + + // Try to cast to our type , considering provider only supports a single range per view + auto other = dynamic_cast(range); + if (other && other->m_view.view() == m_view.view()) { + *pRetVal = TRUE; + } else { + *pRetVal = FALSE; + } return S_OK; } @@ -34,7 +50,10 @@ HRESULT __stdcall CompositionTextRangeProvider::CompareEndpoints( ITextRangeProvider *targetRange, TextPatternRangeEndpoint targetEndpoint, int *pRetVal) { - // no-op + if (pRetVal == nullptr) + return E_POINTER; + + // For a single-range provider, always equal: *pRetVal = 0; return S_OK; } @@ -98,13 +117,13 @@ HRESULT __stdcall CompositionTextRangeProvider::GetAttributeValue(TEXTATTRIBUTEI textTransform = props->textAttributes.textTransform.value(); } if (fontVariant == facebook::react::FontVariant::SmallCaps) { - return CapStyle_SmallCap; + pRetVal->lVal = CapStyle_SmallCap; } else if (textTransform == facebook::react::TextTransform::Capitalize) { - return CapStyle_Titling; + pRetVal->lVal = CapStyle_Titling; } else if (textTransform == facebook::react::TextTransform::Lowercase) { - return CapStyle_None; + pRetVal->lVal = CapStyle_None; } else if (textTransform == facebook::react::TextTransform::Uppercase) { - return CapStyle_AllCap; + pRetVal->lVal = CapStyle_AllCap; } } else if (attributeId == UIA_FontNameAttributeId) { pRetVal->vt = VT_BSTR; @@ -282,6 +301,8 @@ HRESULT __stdcall CompositionTextRangeProvider::ScrollIntoView(BOOL alignToTop) return S_OK; } +// All the below methods should be implemented once the selection comes for paragraph and TextInput + HRESULT __stdcall CompositionTextRangeProvider::AddToSelection() { // no-op return S_OK;