Skip to content

Commit 8362699

Browse files
committed
tweaks
1 parent 10dfa26 commit 8362699

3 files changed

Lines changed: 44 additions & 8 deletions

File tree

docs/api/user-event.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ await user.accessibilityAction(slider, 'increment');
312312

313313
Simulates an assistive technology (e.g. a screen reader) triggering the named accessibility action on a given element, invoking its `onAccessibilityAction` handler.
314314

315-
The `actionName` autocompletes the [standard React Native actions](https://reactnative.dev/docs/accessibility#accessibility-actions) (`activate`, `increment`, `decrement`, `longpress`, `magicTap`, `escape`), but any custom action name is accepted.
315+
The `actionName` autocompletes the [standard React Native actions](https://reactnative.dev/docs/accessibility#accessibility-actions) (`activate`, `increment`, `decrement`, `longpress`, `magicTap`, `escape`, `expand`, `collapse`), but any custom action name is accepted.
316316

317317
Just like a real assistive technology, the action must be reachable by the user, otherwise an error is thrown:
318318

src/user-event/accessibility-action/accessibility-action.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import type {
2-
AccessibilityActionInfo,
3-
AccessibilityActionName as ReactNativeAccessibilityActionName,
4-
} from 'react-native';
1+
import type { AccessibilityActionInfo } from 'react-native';
52
import type { TestInstance } from 'test-renderer';
63

74
import { buildAccessibilityActionEvent } from '../../event-builder';
@@ -14,12 +11,22 @@ import { dispatchEvent } from '../utils';
1411

1512
/**
1613
* Standard accessibility action names recognized by React Native (`activate`,
17-
* `increment`, `decrement`, `longpress`, `magicTap`, `escape`). Custom action
18-
* names are supported as well, hence the `string` fallback.
14+
* `increment`, `decrement`, `longpress`, `magicTap`, `escape`, `expand`,
15+
* `collapse`). Custom action names are supported as well, hence the `string`
16+
* fallback.
1917
*
2018
* @see https://reactnative.dev/docs/accessibility#accessibility-actions
2119
*/
22-
export type AccessibilityActionName = StringWithAutocomplete<ReactNativeAccessibilityActionName>;
20+
export type AccessibilityActionName = StringWithAutocomplete<
21+
| 'activate'
22+
| 'increment'
23+
| 'decrement'
24+
| 'longpress'
25+
| 'magicTap'
26+
| 'escape'
27+
| 'expand'
28+
| 'collapse'
29+
>;
2330

2431
/**
2532
* Simulate an assistive technology (e.g. screen reader) triggering an

website/docs/14.x/docs/api/events/user-event.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,32 @@ The sequence of events depends on whether the scroll includes an optional moment
294294
- `momentumScrollBegin`
295295
- `scroll` (multiple events)
296296
- `momentumScrollEnd`
297+
298+
## `accessibilityAction()`
299+
300+
```ts
301+
accessibilityAction(
302+
instance: TestInstance,
303+
actionName: string,
304+
): Promise<void>
305+
```
306+
307+
Example
308+
309+
```ts
310+
const user = userEvent.setup();
311+
await user.accessibilityAction(slider, 'increment');
312+
```
313+
314+
Simulates an assistive technology (e.g. a screen reader) triggering the named accessibility action on a given element, invoking its `onAccessibilityAction` handler.
315+
316+
The `actionName` autocompletes the [standard React Native actions](https://reactnative.dev/docs/accessibility#accessibility-actions) (`activate`, `increment`, `decrement`, `longpress`, `magicTap`, `escape`, `expand`, `collapse`), but any custom action name is accepted.
317+
318+
Just like a real assistive technology, the action must be reachable by the user, otherwise an error is thrown:
319+
320+
- the action must be declared in the element's `accessibilityActions` prop,
321+
- the element must not be disabled (via `aria-disabled` or `accessibilityState={{ disabled: true }}`).
322+
323+
### Sequence of events
324+
325+
- `accessibilityAction`

0 commit comments

Comments
 (0)