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
5 changes: 5 additions & 0 deletions .changeset/two-forks-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fluentui-react-native/components": patch
---

Declare Radio's native Select action and project caller-owned selection to UI Automation without synthesizing presses or changing the selected value.
23 changes: 13 additions & 10 deletions packages/agentic/components/src/components/radio/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ rather than explicitly hiding the indicator and text children.
- **RAD-002:** Render the indicator, dot, label, and optional supporting text
in the fixed order.
- **RAD-003:** Render externally owned checked state without self-selection
and preserve press reporting.
and preserve press reporting. Declare the native Select action and project
the same owned value through native selection state.
- **RAD-004:** Apply selection, disabled, hovered, pressed, and user-style
precedence to the documented token bindings.
- **RAD-005:** Expose radio semantics, accessible naming, disabled behavior,
Expand All @@ -70,8 +71,10 @@ These hook options do not add new component props. Scenes require `ThemedRoot`.
## Platform behavior

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

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

## Conformance

| Requirement | Evidence |
| ----------- | -------------------------------------------------------- |
| RAD-001 | `radio.types.ts`, `useRadio.ts`, `radio.types.test.ts` |
| RAD-002 | `renderRadio.tsx`, `useRadioStyles.ts`, `radio.test.tsx` |
| RAD-003 | `useRadio.ts`, `radio.test.tsx`, `radio.stories.tsx` |
| RAD-004 | `radio.styles.ts`, `useRadioStyles.ts`, `radio.test.tsx` |
| RAD-005 | `useRadio.ts`, `useRadioStyles.ts`, `radio.test.tsx` |
| Requirement | Evidence |
| ----------- | ------------------------------------------------------------------------- |
| RAD-001 | `radio.types.ts`, `useRadio.ts`, `radio.types.test.ts` |
| RAD-002 | `renderRadio.tsx`, `useRadioStyles.ts`, `radio.test.tsx` |
| RAD-003 | `useRadio.ts`, `radio.test.tsx`, `radio.stories.tsx` |
| RAD-004 | `radio.styles.ts`, `useRadioStyles.ts`, `radio.test.tsx` |
| RAD-005 | `useRadio.ts`, `useRadioStyles.ts`, `radio.test.tsx`, `radio.stories.tsx` |
96 changes: 94 additions & 2 deletions packages/agentic/components/src/components/radio/radio.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
import { useState } from 'react';
import type { ReactNode } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import type { AccessibilityActionEvent } from 'react-native';
import type { WdioStory } from '@fluentui-react-native/storybook-desktop/testing';

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

import { Radio } from './radio';
import type { RadioProps } from './radio.types';
import { StoryStatus } from '../../common/StoryStatus.story-helpers';

type StoryGroupProps = {
children: ReactNode;
Expand Down Expand Up @@ -48,12 +52,100 @@ const meta: Meta<typeof Radio> = {

export default meta;

type Story = StoryObj<typeof Radio>;
type Story = WdioStory<StoryObj<typeof Radio>>;

export const Default: Story = {};

export const NativeSelectionSemantics: Story = {
render: () => {
const Scene = () => {
const [actions, setActions] = useState(0);
const [presses, setPresses] = useState(0);
const [lastAction, setLastAction] = useState('none');
const recordAction = (event: AccessibilityActionEvent) => {
setLastAction(event.nativeEvent.actionName);
setActions((value) => value + 1);
};
return (
<View style={styles.story}>
<Radio
label="Unselected option"
selected={false}
testID="radio-native-off"
onAccessibilityAction={recordAction}
onPress={() => setPresses((value) => value + 1)}
/>
<Radio label="Selected option" selected testID="radio-native-on" />
<Radio
label="Disabled option"
selected
disabled
testID="radio-native-disabled"
onAccessibilityAction={recordAction}
onPress={() => setPresses((value) => value + 1)}
/>
<StoryStatus testID="radio-native-actions">{String(actions)}</StoryStatus>
<StoryStatus testID="radio-native-presses">{String(presses)}</StoryStatus>
<StoryStatus testID="radio-native-last-action">{lastAction}</StoryStatus>
</View>
);
};
return <Scene />;
},
wdio: {
'RAD-003 RAD-005 Win32 exposes native RadioButton selection, names and disabled state': async ({ browser, expect, platform, skip }) => {
if (platform !== 'win32') {
skip('This case qualifies Win32 UI Automation SelectionItem projection.');
return;
}
for (const [id, name, selected] of [
['radio-native-off', 'Unselected option', false],
['radio-native-on', 'Selected option', true],
['radio-native-disabled', 'Disabled option', true],
] as const) {
const radio = await browser.$(`~${id}`);
expect(await radio.getTagName()).toBe('radio');
expect(await radio.getProperty('name')).toBe(name);
expect(await radio.getProperty('selected')).toBe(selected);
}
await expect(await browser.$('~radio-native-disabled')).toBeDisabled();
},
'RAD-003 Win32 Select forwards once without self-selection or presses and disabled public activation rejects': async ({
browser,
expect,
platform,
skip,
}) => {
if (platform !== 'win32') {
skip('This case qualifies Win32 UI Automation Select transport.');
return;
}
const radio = await browser.$('~radio-native-off');
const disabled = await browser.$('~radio-native-disabled');
const actions = await browser.$('~radio-native-actions');
const presses = await browser.$('~radio-native-presses');
await expect(actions).toHaveAttribute('name', '0');
await radio.click();
await expect(actions).toHaveAttribute('name', '1');
await expect(await browser.$('~radio-native-last-action')).toHaveAttribute('name', 'Select');
await expect(presses).toHaveAttribute('name', '0');
expect(await radio.getProperty('selected')).toBe(false);
let rejection: unknown;
try {
await disabled.click();
} catch (error) {
rejection = error;
}
expect(rejection).toBeDefined();
await expect(actions).toHaveAttribute('name', '1');
await expect(presses).toHaveAttribute('name', '0');
expect(await disabled.getProperty('selected')).toBe(true);
},
},
};

export const Overview: Story = {
render: ({ label, secondaryText }) => (
render: ({ label, secondaryText }: RadioProps) => (
<View style={styles.story}>
<StoryGroup label="Selection">
<Radio label={label} secondaryText={secondaryText} showSecondaryText />
Expand Down
51 changes: 47 additions & 4 deletions packages/agentic/components/src/components/radio/radio.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsxImportSource @fluentui-react-native/framework-base */
import { StyleSheet } from 'react-native';
import { Platform, StyleSheet } from 'react-native';
import type { ComponentProps } from 'react';

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

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

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

expect(root).toBeDisabled();
expect(root.props.focusable).toBe(false);
expect(root.props.accessibilityState).toEqual({ busy: true, checked: false, disabled: true });
expect(root.props.accessibilityState).toEqual({ busy: true, checked: false, selected: false, disabled: true });
});

it('applies user styles last and allows constrained labels to shrink', async () => {
Expand Down Expand Up @@ -168,4 +168,47 @@ describe('Radio', () => {
importantForAccessibility: 'no-hide-descendants',
});
});

it.each([
['win32', 'Select'],
['windows', 'select'],
['macos', 'Select'],
] as const)('declares the native selection action on %s', async (platform, actionName) => {
const replacement = jest.replaceProperty(Platform, 'OS', platform as typeof Platform.OS);
try {
const component = await renderRadio({});
expect(getRoot(component).props.accessibilityActions).toEqual([{ name: actionName }]);
} finally {
replacement.restore();
}
});

it('preserves caller action labels and deduplicates selection declarations', async () => {
const component = await renderRadio({
accessibilityActions: [{ name: 'Select', label: 'Choose option' }, { name: 'Select' }, { name: 'custom' }],
});
expect(getRoot(component).props.accessibilityActions).toEqual([{ name: 'Select', label: 'Choose option' }, { name: 'custom' }]);
});

it.each([false, true])('owns native checked and selection state when selected is %s', async (selected) => {
const component = await renderRadio({
selected,
accessibilityState: { busy: true, checked: !selected, selected: !selected },
'aria-checked': !selected,
'aria-selected': !selected,
});
expect(getRoot(component).props.accessibilityState).toEqual({ busy: true, checked: selected, selected, disabled: false });
});

it.each([false, true])('forwards the original native action without pressing or selecting when disabled is %s', async (disabled) => {
const onAccessibilityAction = jest.fn();
const onPress = jest.fn();
const component = await renderRadio({ disabled, selected: false, onAccessibilityAction, onPress });
const event = { nativeEvent: { actionName: 'Select' } };
getRoot(component).props.onAccessibilityAction(event);
expect(onAccessibilityAction).toHaveBeenCalledTimes(1);
expect(onAccessibilityAction).toHaveBeenCalledWith(event);
expect(onPress).not.toHaveBeenCalled();
expect(getRoot(component).props.accessibilityState).toMatchObject({ checked: false, selected: false });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ value and cannot announce decorative descendants separately.
The owning group must provide a group name and any positional or peer
relationship information.

The root declares the platform's resolved Select action, preserving caller
actions and labels. UIA RadioButton uses SelectionItem.IsSelected rather than
Toggle.ToggleState, so the externally owned value also owns native selected
state and takes precedence over conflicting checked/selected ARIA aliases.
Native actions are forwarded unchanged, once, to onAccessibilityAction; Radio
does not synthesize onPress or select itself. An owner supporting native Select
updates its own value from that event. Other native endpoints require separate
qualification.

The focus target follows the [shared focus visual policy](../../../../references/higher-order-components.md#focus-visual-policy).
Windows/macOS default to the native ring, with no custom subtree. Win32 defaults
to a private `FocusRing` slot. Its configured ring Views remain mounted on the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ their corresponding caller handlers are forwarded. Disabled state prevents
activation and focus. Pressing reports through `onPress`; Radio never changes
its own selected value.

Native Select is a separate accessibility transport. The caller handles
onAccessibilityAction to update its owned value; the component only declares
the action and forwards the original event, without manufacturing onPress.

On Windows and macOS, native Pressable behavior activates a focused radio.

Hover and press states change the token-derived colors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
},
{
"id": "RAD-005",
"evidence": ["useRadio.ts", "useRadioStyles.ts", "radio.test.tsx"]
"evidence": ["useRadio.ts", "useRadioStyles.ts", "radio.test.tsx", "radio.stories.tsx"]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ component does not clear a selected peer or manage directional navigation, so
the surrounding group must perform those duties. Use `disabled` only for an
unavailable option, not to represent an unselected one.

To support native selection, handle onAccessibilityAction as well as onPress.
Compare its actionName with
resolveAccessibilityAction('select', Platform.OS).name and update the
group's owned value. Import the resolver from framework-base. Radio declares
the action; the caller must not synthesize a press.

## Scene root

Render the scene inside `ThemedRoot` so focus policy can query `useRootSettings`.
Expand Down
8 changes: 6 additions & 2 deletions packages/agentic/components/src/components/radio/useRadio.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Pressable } from 'react-native';
import { Platform, Pressable } from 'react-native';

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

Expand All @@ -27,14 +27,18 @@ export function useRadio_unstable(props: RadioProps): RadioState {
const themeState = useThemeState();
const [pressableProps, pressableState, focusBinding] = useFocusablePressable({
...rest,
accessibilityActions: resolveAccessibilityAction('select', Platform.OS, rest.accessibilityActions).accessibilityActions,
accessibilityLabel: accessibilityLabel ?? label,
accessibilityHint: accessibilityHint ?? (showSecondaryText ? secondaryText : undefined),
accessibilityRole: 'radio',
accessibilityState: {
...accessibilityState,
checked: selected,
selected,
disabled,
},
'aria-checked': selected,
'aria-selected': selected,
accessible: rest.accessible ?? true,
disabled,
focusable: !disabled && (rest.focusable ?? true),
Expand Down
1 change: 1 addition & 0 deletions packages/agentic/components/tsconfig.stories.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"src/components/menu/menu.stories.tsx",
"src/components/menu-button/menu-button.stories.tsx",
"src/components/popover/popover.stories.tsx",
"src/components/radio/radio.stories.tsx",
"src/components/skeleton/skeleton.stories.tsx",
"src/components/spinner/spinner.stories.tsx",
"src/components/switch/switch.stories.tsx",
Expand Down
Loading