Skip to content

Commit b72b6b3

Browse files
[Fabric] Raising UIA Event if Toggle State Changes in Switch Component (#15023)
* Update Toggle State to Narrator * Yarn Change * Review Changes * Review Changes 2.0
1 parent c930bac commit b72b6b3

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "[Fabric] Raising UIA Event if Toggle State Changes in Switch Component",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/Fabric/Composition/SwitchComponentView.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <Fabric/AbiViewProps.h>
1010
#include "CompositionDynamicAutomationProvider.h"
1111
#include "RootComponentView.h"
12+
#include "UiaHelpers.h"
1213

1314
namespace winrt::Microsoft::ReactNative::Composition::implementation {
1415

@@ -80,6 +81,16 @@ void SwitchComponentView::updateProps(
8081
m_visualUpdateRequired = true;
8182
}
8283

84+
if (oldViewProps.value != newViewProps.value) {
85+
if (UiaClientsAreListening()) {
86+
winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
87+
EnsureUiaProvider(),
88+
UIA_ToggleToggleStatePropertyId,
89+
oldViewProps.value ? ToggleState_On : ToggleState_Off,
90+
newViewProps.value ? ToggleState_On : ToggleState_Off);
91+
}
92+
}
93+
8394
Super::updateProps(props, oldProps);
8495
}
8596

vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ void UpdateUiaProperty(winrt::IInspectable provider, PROPERTYID propId, bool old
166166
UiaRaiseAutomationPropertyChangedEvent(spProviderSimple.get(), propId, CComVariant(oldValue), CComVariant(newValue));
167167
}
168168

169+
void UpdateUiaProperty(winrt::IInspectable provider, PROPERTYID propId, int oldValue, int newValue) noexcept {
170+
auto spProviderSimple = provider.try_as<IRawElementProviderSimple>();
171+
172+
if (spProviderSimple == nullptr || oldValue == newValue || !WasUiaPropertyAdvised(spProviderSimple, propId))
173+
return;
174+
175+
UiaRaiseAutomationPropertyChangedEvent(spProviderSimple.get(), propId, CComVariant(oldValue), CComVariant(newValue));
176+
}
177+
169178
void UpdateUiaProperty(
170179
winrt::IInspectable provider,
171180
PROPERTYID propId,

vnext/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ void UpdateUiaProperty(
2929
bool oldValue,
3030
bool newValue) noexcept;
3131

32+
void UpdateUiaProperty(
33+
winrt::Windows::Foundation::IInspectable provider,
34+
PROPERTYID propId,
35+
int oldValue,
36+
int newValue) noexcept;
37+
3238
void UpdateUiaProperty(
3339
winrt::Windows::Foundation::IInspectable provider,
3440
PROPERTYID propId,

0 commit comments

Comments
 (0)