Skip to content

Commit 2f05043

Browse files
author
Konstantin Marushchak
committed
revert(modal): keep the scrim reachable by assistive technology
1 parent c0b1669 commit 2f05043

4 files changed

Lines changed: 146 additions & 247 deletions

File tree

‎src/components/Modal.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export type Props = {
3232
* Callback that is called when the user dismisses the modal.
3333
*/
3434
onDismiss?: () => void;
35+
/**
36+
* Accessibility label for the overlay. This is read by the screen reader when the user taps outside the modal.
37+
*/
38+
overlayAccessibilityLabel?: string;
3539
/**
3640
* Accessible name for the modal.
3741
*/
@@ -131,6 +135,7 @@ function Modal({
131135
dismissable = true,
132136
dismissableBackButton = dismissable,
133137
visible = false,
138+
overlayAccessibilityLabel = 'Close modal',
134139
'aria-label': ariaLabel,
135140
overlayTestID,
136141
onDismiss = () => {},
@@ -234,11 +239,14 @@ function Modal({
234239
testID={testID}
235240
>
236241
<AnimatedPressable
242+
aria-label={overlayAccessibilityLabel}
243+
role="button"
237244
disabled={!dismissable}
238-
aria-hidden
239245
onPress={dismissable ? onDismissCallback : undefined}
240246
style={[styles.backdrop, backdropStyle, backdropTransitionStyle]}
241247
testID={overlayTestID}
248+
importantForAccessibility={dismissable ? 'auto' : 'no'}
249+
accessible={dismissable}
242250
/>
243251
<View
244252
style={[

‎src/components/__tests__/Dialog.test.tsx‎

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const BackHandler = RNBackHandler as BackHandlerStatic;
2323
describe('Dialog', () => {
2424
it('should render passed children', async () => {
2525
await render(
26-
<Dialog visible testID="dialog" overlayTestID="backdrop">
26+
<Dialog visible testID="dialog">
2727
<Text>This is simple dialog</Text>
2828
</Dialog>
2929
);
@@ -36,20 +36,12 @@ describe('Dialog', () => {
3636
it('should call onDismiss when dismissable', async () => {
3737
const onDismiss = jest.fn();
3838
await render(
39-
<Dialog
40-
visible
41-
onDismiss={onDismiss}
42-
dismissable
43-
testID="dialog"
44-
overlayTestID="backdrop"
45-
>
39+
<Dialog visible onDismiss={onDismiss} dismissable testID="dialog">
4640
<Text>This is simple dialog</Text>
4741
</Dialog>
4842
);
4943

50-
await userEvent.press(
51-
screen.getByTestId('backdrop', { includeHiddenElements: true })
52-
);
44+
await userEvent.press(screen.getByLabelText('Close modal'));
5345

5446
await act(() => {
5547
jest.runAllTimers();
@@ -60,20 +52,12 @@ describe('Dialog', () => {
6052
it('should not call onDismiss when dismissable is false', async () => {
6153
const onDismiss = jest.fn();
6254
await render(
63-
<Dialog
64-
visible
65-
onDismiss={onDismiss}
66-
dismissable={false}
67-
testID="dialog"
68-
overlayTestID="backdrop"
69-
>
55+
<Dialog visible onDismiss={onDismiss} dismissable={false} testID="dialog">
7056
<Text>This is simple dialog</Text>
7157
</Dialog>
7258
);
7359

74-
await userEvent.press(
75-
screen.getByTestId('backdrop', { includeHiddenElements: true })
76-
);
60+
await userEvent.press(screen.getByLabelText('Close modal'));
7761

7862
await act(() => {
7963
jest.runAllTimers();
@@ -91,15 +75,12 @@ describe('Dialog', () => {
9175
dismissable={false}
9276
dismissableBackButton
9377
testID="dialog"
94-
overlayTestID="backdrop"
9578
>
9679
<Text>This is simple dialog</Text>
9780
</Dialog>
9881
);
9982

100-
await userEvent.press(
101-
screen.getByTestId('backdrop', { includeHiddenElements: true })
102-
);
83+
await userEvent.press(screen.getByLabelText('Close modal'));
10384

10485
await act(() => {
10586
jest.runAllTimers();

0 commit comments

Comments
 (0)