Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Components can provide a default accessible name Text component falls back to the content if accessibleLabel isn't set",
"packageName": "react-native-windows",
"email": "26607885+chrisglein@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::GetPropertyValue(PROPERT
switch (propertyId) {
case UIA_ControlTypePropertyId: {
pRetVal->vt = VT_I4;
auto role = props->accessibilityRole == "" ? baseView.get()->DefaultControlType() : props->accessibilityRole;
auto role = props->accessibilityRole.empty() ? baseView->DefaultControlType() : props->accessibilityRole;
pRetVal->lVal = GetControlType(role);
break;
}
Expand All @@ -247,7 +247,8 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::GetPropertyValue(PROPERT
}
case UIA_NamePropertyId: {
pRetVal->vt = VT_BSTR;
auto wideName = ::Microsoft::Common::Unicode::Utf8ToUtf16(props->accessibilityLabel);
auto wideName = ::Microsoft::Common::Unicode::Utf8ToUtf16(
props->accessibilityLabel.empty() ? baseView->DefaultAccessibleName() : props->accessibilityLabel);
pRetVal->bstrVal = SysAllocString(wideName.c_str());
hr = pRetVal->bstrVal != nullptr ? S_OK : E_OUTOFMEMORY;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,10 @@ void CompositionBaseComponentView::updateAccessibilityProps(
provider, UIA_IsKeyboardFocusablePropertyId, oldViewProps.focusable, newViewProps.focusable);

winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
provider, UIA_NamePropertyId, oldViewProps.accessibilityLabel, newViewProps.accessibilityLabel);
provider,
UIA_NamePropertyId,
oldViewProps.accessibilityLabel,
newViewProps.accessibilityLabel.empty() ? DefaultAccessibleName() : newViewProps.accessibilityLabel);

winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
provider,
Expand Down Expand Up @@ -1219,6 +1222,10 @@ std::string CompositionBaseComponentView::DefaultControlType() const noexcept {
return "group";
}

std::string CompositionBaseComponentView::DefaultAccessibleName() const noexcept {
return "";
}

CompositionViewComponentView::CompositionViewComponentView(
const winrt::Microsoft::ReactNative::Composition::ICompositionContext &compContext,
facebook::react::Tag tag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct CompositionBaseComponentView : public IComponentView,
winrt::IInspectable EnsureUiaProvider() noexcept override;

virtual std::string DefaultControlType() const noexcept;
virtual std::string DefaultAccessibleName() const noexcept;

protected:
std::array<winrt::Microsoft::ReactNative::Composition::SpriteVisual, SpecialBorderLayerCount>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void ParagraphComponentView::updateProps(
updateTextAlignment(newViewProps.textAttributes.alignment);
}

updateAccessibilityProps(oldViewProps, newViewProps);
updateBorderProps(oldViewProps, newViewProps);

m_props = std::static_pointer_cast<facebook::react::ParagraphProps const>(props);
Expand Down Expand Up @@ -479,6 +480,10 @@ std::string ParagraphComponentView::DefaultControlType() const noexcept {
return "text";
}

std::string ParagraphComponentView::DefaultAccessibleName() const noexcept {
return m_attributedStringBox.getValue().getString();
}

winrt::Microsoft::ReactNative::Composition::IVisual ParagraphComponentView::Visual() const noexcept {
return m_visual;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ struct ParagraphComponentView : CompositionBaseComponentView {
facebook::react::SharedTouchEventEmitter touchEventEmitterAtPoint(facebook::react::Point pt) noexcept override;

winrt::Microsoft::ReactNative::Composition::IVisual Visual() const noexcept override;
virtual std::string DefaultControlType() const noexcept;
virtual std::string DefaultControlType() const noexcept override;
virtual std::string DefaultAccessibleName() const noexcept override;

private:
ParagraphComponentView(
Expand Down