Skip to content

Commit 2dea730

Browse files
Mahmoud-SKgorhom
authored andcommitted
feat: added accessibility overrides support (#1288)(by @Mahmoud-SK)
* Added accessibility to the bottomSheet component * Accessibility changes - BottomSheetBackdrop * Accessibility changes - BottomSheetHandle * Minor adjustments after review * removed unused spread operator * fix: removed change announcement removed the change announcement part of the code, and the ..rest from the two mentioned files.
1 parent 65b5dc0 commit 2dea730

File tree

11 files changed

+122
-26
lines changed

11 files changed

+122
-26
lines changed

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ import {
7575
INITIAL_CONTAINER_OFFSET,
7676
INITIAL_VALUE,
7777
DEFAULT_DYNAMIC_SIZING,
78+
DEFAULT_ACCESSIBLE,
79+
DEFAULT_ACCESSIBILITY_LABEL,
80+
DEFAULT_ACCESSIBILITY_ROLE
7881
} from './constants';
7982
import type { BottomSheetMethods, Insets } from '../../types';
8083
import type { BottomSheetProps, AnimateToPositionType } from './types';
@@ -159,6 +162,13 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
159162
backgroundComponent,
160163
footerComponent,
161164
children: Content,
165+
166+
// accessibility
167+
accessible: _providedAccessible = DEFAULT_ACCESSIBLE,
168+
accessibilityLabel:
169+
_providedAccessibilityLabel = DEFAULT_ACCESSIBILITY_LABEL,
170+
accessibilityRole:
171+
_providedAccessibilityRole = DEFAULT_ACCESSIBILITY_ROLE,
162172
} = props;
163173
//#endregion
164174

@@ -1635,6 +1645,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
16351645
<Animated.View
16361646
pointerEvents="box-none"
16371647
style={contentMaskContainerStyle}
1648+
accessible={_providedAccessible ?? undefined}
1649+
accessibilityRole={_providedAccessibilityRole ?? undefined}
1650+
accessibilityLabel={_providedAccessibilityLabel ?? undefined}
16381651
>
16391652
<BottomSheetDraggableView
16401653
key="BottomSheetRootDraggableView"

src/components/bottomSheet/constants.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ const INITIAL_CONTAINER_OFFSET = {
3333
const INITIAL_HANDLE_HEIGHT = -999;
3434
const INITIAL_POSITION = SCREEN_HEIGHT;
3535

36+
// accessibility
37+
const DEFAULT_ACCESSIBLE = true;
38+
const DEFAULT_ACCESSIBILITY_LABEL = 'Bottom Sheet';
39+
const DEFAULT_ACCESSIBILITY_ROLE = 'adjustable';
40+
const DEFAULT_ENABLE_ACCESSIBILITY_CHANGE_ANNOUNCEMENT = true;
41+
const DEFAULT_ACCESSIBILITY_POSITION_CHANGE_ANNOUNCEMENT = (
42+
positionInScreen: string
43+
) => `Bottom sheet snapped to ${positionInScreen}% of the screen`;
44+
3645
export {
3746
DEFAULT_HANDLE_HEIGHT,
3847
DEFAULT_OVER_DRAG_RESISTANCE_FACTOR,
@@ -53,4 +62,10 @@ export {
5362
INITIAL_HANDLE_HEIGHT,
5463
INITIAL_SNAP_POINT,
5564
INITIAL_VALUE,
65+
// accessibility
66+
DEFAULT_ACCESSIBLE,
67+
DEFAULT_ACCESSIBILITY_LABEL,
68+
DEFAULT_ACCESSIBILITY_ROLE,
69+
DEFAULT_ENABLE_ACCESSIBILITY_CHANGE_ANNOUNCEMENT,
70+
DEFAULT_ACCESSIBILITY_POSITION_CHANGE_ANNOUNCEMENT,
5671
};

src/components/bottomSheet/types.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import type {
1717
KEYBOARD_BLUR_BEHAVIOR,
1818
KEYBOARD_INPUT_MODE,
1919
} from '../../constants';
20-
import type { GestureEventsHandlersHookType } from '../../types';
20+
import type {
21+
GestureEventsHandlersHookType,
22+
NullableAccessibilityProps,
23+
} from '../../types';
2124

2225
export interface BottomSheetProps
2326
extends BottomSheetAnimationConfigs,
@@ -31,7 +34,8 @@ export interface BottomSheetProps
3134
| 'waitFor'
3235
| 'simultaneousHandlers'
3336
>
34-
> {
37+
>,
38+
Omit<NullableAccessibilityProps, 'accessibilityHint'> {
3539
//#region configuration
3640
/**
3741
* Initial snap point index, provide `-1` to initiate bottom sheet in closed state.

src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import {
1919
DEFAULT_DISAPPEARS_ON_INDEX,
2020
DEFAULT_ENABLE_TOUCH_THROUGH,
2121
DEFAULT_PRESS_BEHAVIOR,
22+
DEFAULT_ACCESSIBLE,
23+
DEFAULT_ACCESSIBILITY_ROLE,
24+
DEFAULT_ACCESSIBILITY_LABEL,
25+
DEFAULT_ACCESSIBILITY_HINT,
2226
} from './constants';
2327
import { styles } from './styles';
2428
import type { BottomSheetDefaultBackdropProps } from './types';
@@ -33,6 +37,10 @@ const BottomSheetBackdropComponent = ({
3337
onPress,
3438
style,
3539
children,
40+
accessible: _providedAccessible = DEFAULT_ACCESSIBLE,
41+
accessibilityRole: _providedAccessibilityRole = DEFAULT_ACCESSIBILITY_ROLE,
42+
accessibilityLabel: _providedAccessibilityLabel = DEFAULT_ACCESSIBILITY_LABEL,
43+
accessibilityHint: _providedAccessibilityHint = DEFAULT_ACCESSIBILITY_HINT,
3644
}: BottomSheetDefaultBackdropProps) => {
3745
//#region hooks
3846
const { snapToIndex, close } = useBottomSheet();
@@ -112,27 +120,33 @@ const BottomSheetBackdropComponent = ({
112120
},
113121
[disappearsOnIndex]
114122
);
123+
124+
const AnimatedView = (
125+
<Animated.View
126+
style={containerStyle}
127+
pointerEvents={pointerEvents}
128+
accessible={_providedAccessible ?? undefined}
129+
accessibilityRole={_providedAccessibilityRole ?? undefined}
130+
accessibilityLabel={_providedAccessibilityLabel ?? undefined}
131+
accessibilityHint={
132+
_providedAccessibilityHint
133+
? _providedAccessibilityHint
134+
: `Tap to ${
135+
typeof pressBehavior === 'string' ? pressBehavior : 'move'
136+
} the Bottom Sheet`
137+
}
138+
>
139+
{children}
140+
</Animated.View>
141+
);
115142
//#endregion
116143

117144
return pressBehavior !== 'none' ? (
118145
<TapGestureHandler onGestureEvent={gestureHandler}>
119-
<Animated.View
120-
style={containerStyle}
121-
pointerEvents={pointerEvents}
122-
accessible={true}
123-
accessibilityRole="button"
124-
accessibilityLabel="Bottom Sheet backdrop"
125-
accessibilityHint={`Tap to ${
126-
typeof pressBehavior === 'string' ? pressBehavior : 'move'
127-
} the Bottom Sheet`}
128-
>
129-
{children}
130-
</Animated.View>
146+
{AnimatedView}
131147
</TapGestureHandler>
132148
) : (
133-
<Animated.View pointerEvents={pointerEvents} style={containerStyle}>
134-
{children}
135-
</Animated.View>
149+
AnimatedView
136150
);
137151
};
138152

src/components/bottomSheetBackdrop/constants.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ const DEFAULT_DISAPPEARS_ON_INDEX = 0;
44
const DEFAULT_ENABLE_TOUCH_THROUGH = false;
55
const DEFAULT_PRESS_BEHAVIOR = 'close' as const;
66

7+
const DEFAULT_ACCESSIBLE = true;
8+
const DEFAULT_ACCESSIBILITY_ROLE = 'button';
9+
const DEFAULT_ACCESSIBILITY_LABEL = 'Bottom sheet backdrop';
10+
const DEFAULT_ACCESSIBILITY_HINT = 'Tap to close the bottom sheet';
11+
712
export {
813
DEFAULT_OPACITY,
914
DEFAULT_APPEARS_ON_INDEX,
1015
DEFAULT_DISAPPEARS_ON_INDEX,
1116
DEFAULT_ENABLE_TOUCH_THROUGH,
1217
DEFAULT_PRESS_BEHAVIOR,
18+
DEFAULT_ACCESSIBLE,
19+
DEFAULT_ACCESSIBILITY_ROLE,
20+
DEFAULT_ACCESSIBILITY_LABEL,
21+
DEFAULT_ACCESSIBILITY_HINT,
1322
};

src/components/bottomSheetBackdrop/types.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { ReactNode } from 'react';
22
import type { ViewProps } from 'react-native';
3-
import type { BottomSheetVariables } from '../../types';
3+
import type {
4+
BottomSheetVariables,
5+
NullableAccessibilityProps,
6+
} from '../../types';
47

58
export interface BottomSheetBackdropProps
69
extends Pick<ViewProps, 'style'>,
@@ -9,7 +12,8 @@ export interface BottomSheetBackdropProps
912
export type BackdropPressBehavior = 'none' | 'close' | 'collapse' | number;
1013

1114
export interface BottomSheetDefaultBackdropProps
12-
extends BottomSheetBackdropProps {
15+
extends BottomSheetBackdropProps,
16+
NullableAccessibilityProps {
1317
/**
1418
* Backdrop opacity.
1519
* @type number

src/components/bottomSheetHandle/BottomSheetHandle.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@ import React, { memo, useMemo } from 'react';
22
import Animated from 'react-native-reanimated';
33
import { styles } from './styles';
44
import type { BottomSheetDefaultHandleProps } from './types';
5+
import {
6+
DEFAULT_ACCESSIBLE,
7+
DEFAULT_ACCESSIBILITY_ROLE,
8+
DEFAULT_ACCESSIBILITY_LABEL,
9+
DEFAULT_ACCESSIBILITY_HINT,
10+
} from './constants';
511

612
const BottomSheetHandleComponent = ({
713
style,
814
indicatorStyle: _indicatorStyle,
915
children,
16+
accessible = DEFAULT_ACCESSIBLE,
17+
accessibilityRole = DEFAULT_ACCESSIBILITY_ROLE,
18+
accessibilityLabel = DEFAULT_ACCESSIBILITY_LABEL,
19+
accessibilityHint = DEFAULT_ACCESSIBILITY_HINT,
1020
}: BottomSheetDefaultHandleProps) => {
1121
// styles
1222
const containerStyle = useMemo(
@@ -23,7 +33,13 @@ const BottomSheetHandleComponent = ({
2333

2434
// render
2535
return (
26-
<Animated.View style={containerStyle}>
36+
<Animated.View
37+
style={containerStyle}
38+
accessible={accessible ?? undefined}
39+
accessibilityRole={accessibilityRole ?? undefined}
40+
accessibilityLabel={accessibilityLabel ?? undefined}
41+
accessibilityHint={accessibilityHint ?? undefined}
42+
>
2743
<Animated.View style={indicatorStyle} />
2844
{children}
2945
</Animated.View>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const DEFAULT_ACCESSIBLE = true;
2+
const DEFAULT_ACCESSIBILITY_ROLE = 'adjustable';
3+
const DEFAULT_ACCESSIBILITY_LABEL = 'Bottom sheet handle';
4+
const DEFAULT_ACCESSIBILITY_HINT =
5+
'Drag up or down to extend or minimize the bottom sheet';
6+
7+
export {
8+
DEFAULT_ACCESSIBLE,
9+
DEFAULT_ACCESSIBILITY_ROLE,
10+
DEFAULT_ACCESSIBILITY_LABEL,
11+
DEFAULT_ACCESSIBILITY_HINT,
12+
};

src/components/bottomSheetHandle/types.d.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import type React from 'react';
22
import type { ViewProps } from 'react-native';
33
import type { AnimateProps } from 'react-native-reanimated';
4-
import type { BottomSheetVariables } from '../../types';
4+
import type {
5+
BottomSheetVariables,
6+
NullableAccessibilityProps,
7+
} from '../../types';
58

69
export interface BottomSheetHandleProps extends BottomSheetVariables {}
710

8-
export interface BottomSheetDefaultHandleProps extends BottomSheetHandleProps {
11+
export interface BottomSheetDefaultHandleProps
12+
extends BottomSheetHandleProps,
13+
NullableAccessibilityProps {
914
/**
1015
* View style to be applied to the handle container.
1116
* @type Animated.AnimateStyle<ViewStyle> | ViewStyle

src/components/bottomSheetHandleContainer/BottomSheetHandleContainer.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ function BottomSheetHandleContainerComponent({
9292
>
9393
<Animated.View
9494
key="BottomSheetHandleContainer"
95-
accessible={true}
96-
accessibilityRole="adjustable"
97-
accessibilityLabel="Bottom Sheet handle"
98-
accessibilityHint="Drag up or down to extend or minimize the Bottom Sheet"
9995
onLayout={handleContainerLayout}
10096
>
10197
<HandleComponent

0 commit comments

Comments
 (0)