Skip to content

Commit d732230

Browse files
fix(radio): expose native selection with the Select action (#4406)
Preserve externally owned state and original accessibility events. Use UI Automation RadioButton SelectionItem state, not an inappropriate Toggle pattern, and add runtime/native regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Srividya Ramaswamy <sriramas@microsoft.com> Copilot-Session: 4b66f3ef-85ac-4405-bd35-dcc167a077b1
1 parent b4ad0e8 commit d732230

10 files changed

Lines changed: 186 additions & 19 deletions

File tree

‎.changeset/two-forks-double.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fluentui-react-native/components": patch
3+
---
4+
5+
Declare Radio's native Select action and project caller-owned selection to UI Automation without synthesizing presses or changing the selected value.

‎packages/agentic/components/src/components/radio/SPEC.md‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ rather than explicitly hiding the indicator and text children.
4646
- **RAD-002:** Render the indicator, dot, label, and optional supporting text
4747
in the fixed order.
4848
- **RAD-003:** Render externally owned checked state without self-selection
49-
and preserve press reporting.
49+
and preserve press reporting. Declare the native Select action and project
50+
the same owned value through native selection state.
5051
- **RAD-004:** Apply selection, disabled, hovered, pressed, and user-style
5152
precedence to the documented token bindings.
5253
- **RAD-005:** Expose radio semantics, accessible naming, disabled behavior,
@@ -70,8 +71,10 @@ These hook options do not add new component props. Scenes require `ThemedRoot`.
7071
## Platform behavior
7172

7273
On Windows and macOS the root is an accessible React Native `Pressable` with
73-
the `radio` role. UIA and AX receive its name, checked value, and disabled
74-
value from the root. Disabled radios cannot be focused or activated. The
74+
the `radio` role. UIA RadioButton exposes its value through SelectionItem,
75+
not the Toggle pattern; the root projects its owned value to both React
76+
Native checked and selected state. Native Select events are forwarded without
77+
synthesizing presses or changing the caller's value. Disabled radios cannot be focused or activated. The
7578
indicator and text subtrees are explicitly hidden from assistive technology so
7679
the named root is the single announced element.
7780

@@ -96,10 +99,10 @@ implemented by the component that renders the radios.
9699

97100
## Conformance
98101

99-
| Requirement | Evidence |
100-
| ----------- | -------------------------------------------------------- |
101-
| RAD-001 | `radio.types.ts`, `useRadio.ts`, `radio.types.test.ts` |
102-
| RAD-002 | `renderRadio.tsx`, `useRadioStyles.ts`, `radio.test.tsx` |
103-
| RAD-003 | `useRadio.ts`, `radio.test.tsx`, `radio.stories.tsx` |
104-
| RAD-004 | `radio.styles.ts`, `useRadioStyles.ts`, `radio.test.tsx` |
105-
| RAD-005 | `useRadio.ts`, `useRadioStyles.ts`, `radio.test.tsx` |
102+
| Requirement | Evidence |
103+
| ----------- | ------------------------------------------------------------------------- |
104+
| RAD-001 | `radio.types.ts`, `useRadio.ts`, `radio.types.test.ts` |
105+
| RAD-002 | `renderRadio.tsx`, `useRadioStyles.ts`, `radio.test.tsx` |
106+
| RAD-003 | `useRadio.ts`, `radio.test.tsx`, `radio.stories.tsx` |
107+
| RAD-004 | `radio.styles.ts`, `useRadioStyles.ts`, `radio.test.tsx` |
108+
| RAD-005 | `useRadio.ts`, `useRadioStyles.ts`, `radio.test.tsx`, `radio.stories.tsx` |

‎packages/agentic/components/src/components/radio/radio.stories.tsx‎

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
import { useState } from 'react';
33
import type { ReactNode } from 'react';
44
import { StyleSheet, Text, View } from 'react-native';
5+
import type { AccessibilityActionEvent } from 'react-native';
6+
import type { WdioStory } from '@fluentui-react-native/storybook-desktop/testing';
57

68
import type { Meta, StoryObj } from '@storybook/react-native';
79

810
import { Radio } from './radio';
11+
import type { RadioProps } from './radio.types';
12+
import { StoryStatus } from '../../common/StoryStatus.story-helpers';
913

1014
type StoryGroupProps = {
1115
children: ReactNode;
@@ -48,12 +52,100 @@ const meta: Meta<typeof Radio> = {
4852

4953
export default meta;
5054

51-
type Story = StoryObj<typeof Radio>;
55+
type Story = WdioStory<StoryObj<typeof Radio>>;
5256

5357
export const Default: Story = {};
5458

59+
export const NativeSelectionSemantics: Story = {
60+
render: () => {
61+
const Scene = () => {
62+
const [actions, setActions] = useState(0);
63+
const [presses, setPresses] = useState(0);
64+
const [lastAction, setLastAction] = useState('none');
65+
const recordAction = (event: AccessibilityActionEvent) => {
66+
setLastAction(event.nativeEvent.actionName);
67+
setActions((value) => value + 1);
68+
};
69+
return (
70+
<View style={styles.story}>
71+
<Radio
72+
label="Unselected option"
73+
selected={false}
74+
testID="radio-native-off"
75+
onAccessibilityAction={recordAction}
76+
onPress={() => setPresses((value) => value + 1)}
77+
/>
78+
<Radio label="Selected option" selected testID="radio-native-on" />
79+
<Radio
80+
label="Disabled option"
81+
selected
82+
disabled
83+
testID="radio-native-disabled"
84+
onAccessibilityAction={recordAction}
85+
onPress={() => setPresses((value) => value + 1)}
86+
/>
87+
<StoryStatus testID="radio-native-actions">{String(actions)}</StoryStatus>
88+
<StoryStatus testID="radio-native-presses">{String(presses)}</StoryStatus>
89+
<StoryStatus testID="radio-native-last-action">{lastAction}</StoryStatus>
90+
</View>
91+
);
92+
};
93+
return <Scene />;
94+
},
95+
wdio: {
96+
'RAD-003 RAD-005 Win32 exposes native RadioButton selection, names and disabled state': async ({ browser, expect, platform, skip }) => {
97+
if (platform !== 'win32') {
98+
skip('This case qualifies Win32 UI Automation SelectionItem projection.');
99+
return;
100+
}
101+
for (const [id, name, selected] of [
102+
['radio-native-off', 'Unselected option', false],
103+
['radio-native-on', 'Selected option', true],
104+
['radio-native-disabled', 'Disabled option', true],
105+
] as const) {
106+
const radio = await browser.$(`~${id}`);
107+
expect(await radio.getTagName()).toBe('radio');
108+
expect(await radio.getProperty('name')).toBe(name);
109+
expect(await radio.getProperty('selected')).toBe(selected);
110+
}
111+
await expect(await browser.$('~radio-native-disabled')).toBeDisabled();
112+
},
113+
'RAD-003 Win32 Select forwards once without self-selection or presses and disabled public activation rejects': async ({
114+
browser,
115+
expect,
116+
platform,
117+
skip,
118+
}) => {
119+
if (platform !== 'win32') {
120+
skip('This case qualifies Win32 UI Automation Select transport.');
121+
return;
122+
}
123+
const radio = await browser.$('~radio-native-off');
124+
const disabled = await browser.$('~radio-native-disabled');
125+
const actions = await browser.$('~radio-native-actions');
126+
const presses = await browser.$('~radio-native-presses');
127+
await expect(actions).toHaveAttribute('name', '0');
128+
await radio.click();
129+
await expect(actions).toHaveAttribute('name', '1');
130+
await expect(await browser.$('~radio-native-last-action')).toHaveAttribute('name', 'Select');
131+
await expect(presses).toHaveAttribute('name', '0');
132+
expect(await radio.getProperty('selected')).toBe(false);
133+
let rejection: unknown;
134+
try {
135+
await disabled.click();
136+
} catch (error) {
137+
rejection = error;
138+
}
139+
expect(rejection).toBeDefined();
140+
await expect(actions).toHaveAttribute('name', '1');
141+
await expect(presses).toHaveAttribute('name', '0');
142+
expect(await disabled.getProperty('selected')).toBe(true);
143+
},
144+
},
145+
};
146+
55147
export const Overview: Story = {
56-
render: ({ label, secondaryText }) => (
148+
render: ({ label, secondaryText }: RadioProps) => (
57149
<View style={styles.story}>
58150
<StoryGroup label="Selection">
59151
<Radio label={label} secondaryText={secondaryText} showSecondaryText />

‎packages/agentic/components/src/components/radio/radio.test.tsx‎

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @jsxImportSource @fluentui-react-native/framework-base */
2-
import { StyleSheet } from 'react-native';
2+
import { Platform, StyleSheet } from 'react-native';
33
import type { ComponentProps } from 'react';
44

55
import { fireEvent } from '@testing-library/react-native';
@@ -46,7 +46,7 @@ describe('Radio', () => {
4646
const root = getRoot(component);
4747

4848
expect(root.props.accessibilityLabel).toBe('Label');
49-
expect(root.props.accessibilityState).toEqual({ checked: false, disabled: false });
49+
expect(root.props.accessibilityState).toEqual({ checked: false, selected: false, disabled: false });
5050
expect(root.props.focusable).toBe(true);
5151
expect(getText(component, 'Label')).toBeOnTheScreen();
5252
expect(component.queryByText('Description')).toBeNull();
@@ -96,7 +96,7 @@ describe('Radio', () => {
9696
const component = await renderRadio({ label: 'Choice', selected: true });
9797
const root = getRoot(component);
9898

99-
expect(root.props.accessibilityState).toEqual({ checked: true, disabled: false });
99+
expect(root.props.accessibilityState).toEqual({ checked: true, selected: true, disabled: false });
100100
expect(StyleSheet.flatten(getTestId(component, 'radio-indicator').props.style).borderColor).toBe(tokens.strokeBrandLoud);
101101
expect(StyleSheet.flatten(getTestId(component, 'radio-dot').props.style)).toMatchObject({
102102
backgroundColor: tokens.foregroundBrandPrimary,
@@ -135,7 +135,7 @@ describe('Radio', () => {
135135

136136
expect(root).toBeDisabled();
137137
expect(root.props.focusable).toBe(false);
138-
expect(root.props.accessibilityState).toEqual({ busy: true, checked: false, disabled: true });
138+
expect(root.props.accessibilityState).toEqual({ busy: true, checked: false, selected: false, disabled: true });
139139
});
140140

141141
it('applies user styles last and allows constrained labels to shrink', async () => {
@@ -168,4 +168,47 @@ describe('Radio', () => {
168168
importantForAccessibility: 'no-hide-descendants',
169169
});
170170
});
171+
172+
it.each([
173+
['win32', 'Select'],
174+
['windows', 'select'],
175+
['macos', 'Select'],
176+
] as const)('declares the native selection action on %s', async (platform, actionName) => {
177+
const replacement = jest.replaceProperty(Platform, 'OS', platform as typeof Platform.OS);
178+
try {
179+
const component = await renderRadio({});
180+
expect(getRoot(component).props.accessibilityActions).toEqual([{ name: actionName }]);
181+
} finally {
182+
replacement.restore();
183+
}
184+
});
185+
186+
it('preserves caller action labels and deduplicates selection declarations', async () => {
187+
const component = await renderRadio({
188+
accessibilityActions: [{ name: 'Select', label: 'Choose option' }, { name: 'Select' }, { name: 'custom' }],
189+
});
190+
expect(getRoot(component).props.accessibilityActions).toEqual([{ name: 'Select', label: 'Choose option' }, { name: 'custom' }]);
191+
});
192+
193+
it.each([false, true])('owns native checked and selection state when selected is %s', async (selected) => {
194+
const component = await renderRadio({
195+
selected,
196+
accessibilityState: { busy: true, checked: !selected, selected: !selected },
197+
'aria-checked': !selected,
198+
'aria-selected': !selected,
199+
});
200+
expect(getRoot(component).props.accessibilityState).toEqual({ busy: true, checked: selected, selected, disabled: false });
201+
});
202+
203+
it.each([false, true])('forwards the original native action without pressing or selecting when disabled is %s', async (disabled) => {
204+
const onAccessibilityAction = jest.fn();
205+
const onPress = jest.fn();
206+
const component = await renderRadio({ disabled, selected: false, onAccessibilityAction, onPress });
207+
const event = { nativeEvent: { actionName: 'Select' } };
208+
getRoot(component).props.onAccessibilityAction(event);
209+
expect(onAccessibilityAction).toHaveBeenCalledTimes(1);
210+
expect(onAccessibilityAction).toHaveBeenCalledWith(event);
211+
expect(onPress).not.toHaveBeenCalled();
212+
expect(getRoot(component).props.accessibilityState).toMatchObject({ checked: false, selected: false });
213+
});
171214
});

‎packages/agentic/components/src/components/radio/spec/accessibility.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ value and cannot announce decorative descendants separately.
1414
The owning group must provide a group name and any positional or peer
1515
relationship information.
1616

17+
The root declares the platform's resolved Select action, preserving caller
18+
actions and labels. UIA RadioButton uses SelectionItem.IsSelected rather than
19+
Toggle.ToggleState, so the externally owned value also owns native selected
20+
state and takes precedence over conflicting checked/selected ARIA aliases.
21+
Native actions are forwarded unchanged, once, to onAccessibilityAction; Radio
22+
does not synthesize onPress or select itself. An owner supporting native Select
23+
updates its own value from that event. Other native endpoints require separate
24+
qualification.
25+
1726
The focus target follows the [shared focus visual policy](../../../../references/higher-order-components.md#focus-visual-policy).
1827
Windows/macOS default to the native ring, with no custom subtree. Win32 defaults
1928
to a private `FocusRing` slot. Its configured ring Views remain mounted on the

‎packages/agentic/components/src/components/radio/spec/interaction.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ their corresponding caller handlers are forwarded. Disabled state prevents
55
activation and focus. Pressing reports through `onPress`; Radio never changes
66
its own selected value.
77

8+
Native Select is a separate accessibility transport. The caller handles
9+
onAccessibilityAction to update its owned value; the component only declares
10+
the action and forwards the original event, without manufacturing onPress.
11+
812
On Windows and macOS, native Pressable behavior activates a focused radio.
913

1014
Hover and press states change the token-derived colors.

‎packages/agentic/components/src/components/radio/spec/source.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
},
107107
{
108108
"id": "RAD-005",
109-
"evidence": ["useRadio.ts", "useRadioStyles.ts", "radio.test.tsx"]
109+
"evidence": ["useRadio.ts", "useRadioStyles.ts", "radio.test.tsx", "radio.stories.tsx"]
110110
}
111111
]
112112
}

‎packages/agentic/components/src/components/radio/spec/usage.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ component does not clear a selected peer or manage directional navigation, so
1818
the surrounding group must perform those duties. Use `disabled` only for an
1919
unavailable option, not to represent an unselected one.
2020

21+
To support native selection, handle onAccessibilityAction as well as onPress.
22+
Compare its actionName with
23+
resolveAccessibilityAction('select', Platform.OS).name and update the
24+
group's owned value. Import the resolver from framework-base. Radio declares
25+
the action; the caller must not synthesize a press.
26+
2127
## Scene root
2228

2329
Render the scene inside `ThemedRoot` so focus policy can query `useRootSettings`.

‎packages/agentic/components/src/components/radio/useRadio.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Pressable } from 'react-native';
1+
import { Platform, Pressable } from 'react-native';
22

3-
import { useFocusablePressable, useSlot } from '@fluentui-react-native/framework-base';
3+
import { resolveAccessibilityAction, useFocusablePressable, useSlot } from '@fluentui-react-native/framework-base';
44
import { useThemeState } from '@fluentui-react-native/design';
55
import { useFocusVisuals } from '../../common/useFocusVisuals';
66

@@ -27,14 +27,18 @@ export function useRadio_unstable(props: RadioProps): RadioState {
2727
const themeState = useThemeState();
2828
const [pressableProps, pressableState, focusBinding] = useFocusablePressable({
2929
...rest,
30+
accessibilityActions: resolveAccessibilityAction('select', Platform.OS, rest.accessibilityActions).accessibilityActions,
3031
accessibilityLabel: accessibilityLabel ?? label,
3132
accessibilityHint: accessibilityHint ?? (showSecondaryText ? secondaryText : undefined),
3233
accessibilityRole: 'radio',
3334
accessibilityState: {
3435
...accessibilityState,
3536
checked: selected,
37+
selected,
3638
disabled,
3739
},
40+
'aria-checked': selected,
41+
'aria-selected': selected,
3842
accessible: rest.accessible ?? true,
3943
disabled,
4044
focusable: !disabled && (rest.focusable ?? true),

‎packages/agentic/components/tsconfig.stories.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"src/components/menu/menu.stories.tsx",
1818
"src/components/menu-button/menu-button.stories.tsx",
1919
"src/components/popover/popover.stories.tsx",
20+
"src/components/radio/radio.stories.tsx",
2021
"src/components/skeleton/skeleton.stories.tsx",
2122
"src/components/spinner/spinner.stories.tsx",
2223
"src/components/switch/switch.stories.tsx",

0 commit comments

Comments
 (0)