Skip to content
Open
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
20 changes: 14 additions & 6 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import * as React from 'react';
import { Platform, StyleSheet, Pressable, View } from 'react-native';
import {
AccessibilityInfo,
Platform,
Pressable,
StyleSheet,
View,
} from 'react-native';
import type { StyleProp, ViewStyle } from 'react-native';

import Animated, {
Expand Down Expand Up @@ -263,13 +269,15 @@ function Modal({

// Transparent views are not in the accessibility tree, so focus has to
// wait for the fade to finish.
const timeout = setTimeout(
focusInitialTarget,
getDuration(DEFAULT_DURATION)
);
const timeout = setTimeout(() => {
focusInitialTarget();
if (Platform.OS === 'ios' && ariaLabel) {
AccessibilityInfo.announceForAccessibility(ariaLabel);
}
}, getDuration(DEFAULT_DURATION));

return () => clearTimeout(timeout);
}, [animatedVisible, focusInitialTarget, getDuration]);
}, [animatedVisible, ariaLabel, focusInitialTarget, getDuration]);

const transitionTimingFunction = cubicBezier(1 / 3, 1, 2 / 3, 1);

Expand Down
23 changes: 23 additions & 0 deletions src/components/__tests__/Dialog.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ComponentProps } from 'react';
import {
AccessibilityInfo,
Text,
StyleSheet,
Platform,
Expand Down Expand Up @@ -418,6 +419,28 @@ describe('Dialog', () => {
expect(screen.getByLabelText('Alert')).toHaveProp('role', 'dialog');
});

it('announces the dialog name on iOS when opening', async () => {
jest.useFakeTimers();
jest.replaceProperty(Platform, 'OS', 'ios');
const announceSpy = jest
.spyOn(AccessibilityInfo, 'announceForAccessibility')
.mockImplementation(() => {});

await render(
<Portal.Host>
<Dialog visible onDismiss={jest.fn()} title="Alert" content="Body" />
</Portal.Host>
);

await act(() => {
jest.runAllTimers();
});

expect(announceSpy).toHaveBeenCalledWith('Alert');
announceSpy.mockRestore();
jest.useRealTimers();
});

it('should render a content', async () => {
await render(
<Portal.Host>
Expand Down
Loading