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

Fix Bug in Accessible/Focusable Behavior #9840

Merged
merged 13 commits into from
Apr 21, 2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Implement Focus Fix",
"packageName": "react-native-windows",
"email": "34109996+chiaramooney@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ bool FrameworkElementViewManager::UpdateProperty(
} else {
xaml::Automation::AutomationProperties::SetAccessibilityView(element, winrt::AccessibilityView::Raw);
}
if (auto control = nodeToUpdate->GetView().try_as<xaml::Controls::Control>()) {
if (control.IsTabStop() != propertyValue.AsBoolean()) {
control.IsTabStop(false);
xaml::Automation::AutomationProperties::SetAccessibilityView(element, winrt::AccessibilityView::Raw);
}
}
chiaramooney marked this conversation as resolved.
Show resolved Hide resolved
} else if (propertyValue.IsNull()) {
element.ClearValue(xaml::Automation::AutomationProperties::AccessibilityViewProperty());
}
Expand Down
21 changes: 21 additions & 0 deletions vnext/Microsoft.ReactNative/Views/ViewViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ViewControl.h"

#include <UI.Xaml.Automation.Peers.h>
#include "DynamicAutomationProperties.h"

#include <JSValueWriter.h>
Expand Down Expand Up @@ -127,6 +128,14 @@ class ViewShadowNode : public ShadowNodeBase {
GetControl().IsTabStop(m_isFocusable);
}

bool IsAccessible() const {
return m_isAccessible;
}

void IsAccessible(bool isAccessible) {
m_isAccessible = isAccessible;
}

bool IsHitTestBrushRequired() const {
return IsRegisteredForMouseEvents();
}
Expand Down Expand Up @@ -251,6 +260,7 @@ class ViewShadowNode : public ShadowNodeBase {
bool m_enableFocusRing = true;
bool m_onClick = false;
bool m_isFocusable = false;
bool m_isAccessible = false;
int32_t m_tabIndex = std::numeric_limits<std::int32_t>::max();

xaml::Controls::ContentControl::GotFocus_revoker m_contentControlGotFocusRevoker{};
Expand Down Expand Up @@ -420,6 +430,11 @@ bool ViewViewManager::UpdateProperty(
pViewShadowNode->TabIndex(std::numeric_limits<std::int32_t>::max());
}
} else {
if (propertyName == "accessible") {
if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::Boolean) {
pViewShadowNode->IsAccessible(propertyValue.AsBoolean());
}
}
ret = Super::UpdateProperty(nodeToUpdate, propertyName, propertyValue);
}
}
Expand Down Expand Up @@ -563,6 +578,12 @@ void ViewViewManager::TryUpdateView(

if (useControl)
pViewShadowNode->GetControl().Content(visualRoot);

if (pViewShadowNode->IsAccessible() != pViewShadowNode->IsFocusable()) {
pViewShadowNode->GetControl().IsTabStop(false);
xaml::Automation::AutomationProperties::SetAccessibilityView(
pViewShadowNode->GetControl(), xaml::Automation::Peers::AccessibilityView::Raw);
}
}

void ViewViewManager::SetLayoutProps(
Expand Down
1 change: 1 addition & 0 deletions vnext/src/Libraries/Components/Button.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class Button extends React.Component<
if (Platform.OS === 'windows') {
return (
<Touchable
accessible={accessible}
accessibilityLabel={accessibilityLabel}
accessibilityHint={accessibilityHint}
accessibilityLanguage={accessibilityLanguage}
Expand Down