Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ControlType values to match corresponding accessibilityRole values #14215

Merged
merged 5 commits into from
Jan 13, 2025
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": "update controltype with accessibilityRole",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "DynamicAutomationProperties.h"

#include <Views/ViewPanel.h>
#include "FrameworkElementViewManager.h"
#include "Unicode.h"
#include "cdebug.h"

Expand Down Expand Up @@ -422,13 +423,24 @@ bool FrameworkElementViewManager::UpdateProperty(
else if (role == "toolbar")
DynamicAutomationProperties::SetAccessibilityRole(
element, winrt::Microsoft::ReactNative::AccessibilityRoles::ToolBar);
else if (role == "list")
else if (role == "list") {
DynamicAutomationProperties::SetAccessibilityRole(
element, winrt::Microsoft::ReactNative::AccessibilityRoles::List);
else if (role == "listitem")
if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::String) {
winrt::hstring controlType = FrameworkElementViewManager::getControlTypeFromAccessibilityRole(
winrt::Microsoft::ReactNative::AccessibilityRoles::List);
FrameworkElementViewManager::setLocalizedControlTypeFromAccessibilityRole(element, controlType);
}
} else if (role == "listitem") {
DynamicAutomationProperties::SetAccessibilityRole(
element, winrt::Microsoft::ReactNative::AccessibilityRoles::ListItem);
else
if (propertyValue.Type() ==
winrt::Microsoft::ReactNative::JSValueType::String) { // Set localized control type
winrt::hstring controlType = FrameworkElementViewManager::getControlTypeFromAccessibilityRole(
winrt::Microsoft::ReactNative::AccessibilityRoles::ListItem);
FrameworkElementViewManager::setLocalizedControlTypeFromAccessibilityRole(element, controlType);
}
} else
DynamicAutomationProperties::SetAccessibilityRole(
element, winrt::Microsoft::ReactNative::AccessibilityRoles::Unknown);
} else if (propertyValue.IsNull()) {
Expand Down Expand Up @@ -823,6 +835,71 @@ bool FrameworkElementViewManager::UpdateProperty(
return true;
}

winrt::hstring FrameworkElementViewManager::getControlTypeFromAccessibilityRole(
winrt::Microsoft::ReactNative::AccessibilityRoles role) {
switch (role) {
case winrt::Microsoft::ReactNative::AccessibilityRoles::Button:
case winrt::Microsoft::ReactNative::AccessibilityRoles::ImageButton:
case winrt::Microsoft::ReactNative::AccessibilityRoles::Switch:
case winrt::Microsoft::ReactNative::AccessibilityRoles::ToggleButton:
return winrt::to_hstring("button");
case winrt::Microsoft::ReactNative::AccessibilityRoles::Link:
return winrt::to_hstring("link");
case winrt::Microsoft::ReactNative::AccessibilityRoles::Image:
return winrt::to_hstring("image");
case winrt::Microsoft::ReactNative::AccessibilityRoles::KeyboardKey:
return winrt::to_hstring("custom");
case winrt::Microsoft::ReactNative::AccessibilityRoles::Text:
case winrt::Microsoft::ReactNative::AccessibilityRoles::Header:
case winrt::Microsoft::ReactNative::AccessibilityRoles::Summary:
case winrt::Microsoft::ReactNative::AccessibilityRoles::Alert:
return winrt::to_hstring("text");
case winrt::Microsoft::ReactNative::AccessibilityRoles::Adjustable:
return winrt::to_hstring("slider");
case winrt::Microsoft::ReactNative::AccessibilityRoles::CheckBox:
return winrt::to_hstring("checkbox");
case winrt::Microsoft::ReactNative::AccessibilityRoles::ComboBox:
return winrt::to_hstring("combobox");
case winrt::Microsoft::ReactNative::AccessibilityRoles::Menu:
return winrt::to_hstring("menu");
case winrt::Microsoft::ReactNative::AccessibilityRoles::MenuBar:
return winrt::to_hstring("menubar");
case winrt::Microsoft::ReactNative::AccessibilityRoles::MenuItem:
return winrt::to_hstring("menuitem");
case winrt::Microsoft::ReactNative::AccessibilityRoles::ProgressBar:
return winrt::to_hstring("progressbar");
case winrt::Microsoft::ReactNative::AccessibilityRoles::Radio:
return winrt::to_hstring("radiobutton");
case winrt::Microsoft::ReactNative::AccessibilityRoles::ScrollBar:
return winrt::to_hstring("scrollbar");
case winrt::Microsoft::ReactNative::AccessibilityRoles::SpinButton:
return winrt::to_hstring("spinner");
case winrt::Microsoft::ReactNative::AccessibilityRoles::Tab:
return winrt::to_hstring("tabitem");
case winrt::Microsoft::ReactNative::AccessibilityRoles::TabList:
return winrt::to_hstring("tab");
case winrt::Microsoft::ReactNative::AccessibilityRoles::ToolBar:
return winrt::to_hstring("toolbar");
case winrt::Microsoft::ReactNative::AccessibilityRoles::List:
return winrt::to_hstring("list");
case winrt::Microsoft::ReactNative::AccessibilityRoles::ListItem:
return winrt::to_hstring("listitem");
case winrt::Microsoft::ReactNative::AccessibilityRoles::None:
case winrt::Microsoft::ReactNative::AccessibilityRoles::Search:
case winrt::Microsoft::ReactNative::AccessibilityRoles::RadioGroup:
case winrt::Microsoft::ReactNative::AccessibilityRoles::Timer:
return winrt::to_hstring("group");
}
return winrt::to_hstring("custom");
}

void FrameworkElementViewManager::setLocalizedControlTypeFromAccessibilityRole(
xaml::UIElement element,
winrt::hstring value) {
auto controlTypeBoxedValue = winrt::Windows::Foundation::PropertyValue::CreateString(value);
element.SetValue(xaml::Automation::AutomationProperties::LocalizedControlTypeProperty(), controlTypeBoxedValue);
}

// Applies a TransformMatrix to the backing UIElement.
// In react-native, rotates and scales are applied about the center of the
// component, unlike XAML. Since the javascript layer sends a non-centered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class REACTWINDOWS_EXPORT FrameworkElementViewManager : public ViewManagerBase {
public:
FrameworkElementViewManager(const Mso::React::IReactContext &context);

static winrt::hstring getControlTypeFromAccessibilityRole(winrt::Microsoft::ReactNative::AccessibilityRoles role);

void setLocalizedControlTypeFromAccessibilityRole(xaml::UIElement element, winrt::hstring value);

void GetNativeProps(const winrt::Microsoft::ReactNative::IJSValueWriter &writer) const override;

// Helper functions related to setting/updating TransformMatrix
Expand Down