Skip to content

Commit d35a594

Browse files
authored
feat: added accessibility props on AutofocusContainer's Touchable container (#300)
* Add type helper PickAccessibleProps to internal package * Add touchableContainerAccessibilityProps * added changesets
1 parent 830673b commit d35a594

5 files changed

Lines changed: 56 additions & 12 deletions

File tree

.changeset/fifty-rice-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@react-native-ama/internal': patch
3+
---
4+
5+
Added `PickAccessibleProps` type helper to AMA internal package

.changeset/six-goats-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@react-native-ama/core': patch
3+
---
4+
5+
Added `touchableContainerAccessibilityProps` prop to `AutofocusContainer` to fix issue with accessible view on container

packages/core/src/components/AutofocusContainer.tsx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
import * as React from 'react';
2-
import { TouchableWithoutFeedback, View, ViewProps } from 'react-native';
2+
import {
3+
TouchableWithoutFeedback,
4+
TouchableWithoutFeedbackProps,
5+
View,
6+
ViewProps,
7+
} from 'react-native';
38

49
import { useFocus } from '../hooks/useFocus';
10+
import { PickAccessibleProps } from '@react-native-ama/internal';
511

6-
type AutofocusContainerProps = React.PropsWithChildren<
7-
| ({
8-
wrapChildrenInAccessibleView?: true;
9-
} & ViewProps)
10-
| {
11-
wrapChildrenInAccessibleView: false;
12-
}
12+
type TouchableAccessibleProps =
13+
PickAccessibleProps<TouchableWithoutFeedbackProps>;
14+
15+
export type AutofocusContainerProps = React.PropsWithChildren<
16+
(
17+
| ({
18+
wrapChildrenInAccessibleView?: true;
19+
} & ViewProps)
20+
| {
21+
wrapChildrenInAccessibleView: false;
22+
}
23+
) & {
24+
/**
25+
* touchableContainerAccessibilityProps is provided as a workaround for any accessibility props that need to be passed to the TouchableWithoutFeedback component which are not recognized on the accessible view.
26+
*/
27+
touchableContainerAccessibilityProps?: TouchableAccessibleProps;
28+
}
1329
>;
1430

1531
export const AutofocusContainer = ({
1632
children,
1733
wrapChildrenInAccessibleView = true,
34+
touchableContainerAccessibilityProps,
1835
...viewProps
1936
}: AutofocusContainerProps) => {
2037
const containerRef = React.useRef(null);
@@ -27,7 +44,9 @@ export const AutofocusContainer = ({
2744
}, [setFocus]);
2845

2946
return wrapChildrenInAccessibleView ? (
30-
<TouchableWithoutFeedback ref={containerRef}>
47+
<TouchableWithoutFeedback
48+
ref={containerRef}
49+
{...touchableContainerAccessibilityProps}>
3150
<View
3251
accessible={true}
3352
testID="autofocusContainer.accessibleView"
@@ -36,7 +55,9 @@ export const AutofocusContainer = ({
3655
</View>
3756
</TouchableWithoutFeedback>
3857
) : (
39-
<TouchableWithoutFeedback ref={containerRef}>
58+
<TouchableWithoutFeedback
59+
ref={containerRef}
60+
{...touchableContainerAccessibilityProps}>
4061
{children}
4162
</TouchableWithoutFeedback>
4263
);

packages/internal/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ export {
6262
export { IS_ANDROID, IS_IOS } from './utils/platformHelpers';
6363

6464
// Types
65-
export { type AMAAccessibilityState, type AccessibilityRoles } from './types';
65+
export {
66+
type AMAAccessibilityState,
67+
type AccessibilityRoles,
68+
type PickAccessibleProps,
69+
} from './types';

packages/internal/src/types.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
/* istanbul ignore file */
21
import type { AccessibilityState } from 'react-native';
32

43
export type AMAAccessibilityState = Pick<AccessibilityState, 'busy'>;
54

5+
export type PickAccessibleProps<T> = {
6+
[K in keyof T as K extends
7+
| `${string}accessible${string}`
8+
| `${string}accessibility${string}`
9+
| `${string}Accessible${string}`
10+
| `${string}Accessibility${string}`
11+
? K
12+
: never]: T[K];
13+
};
14+
615
export type AccessibilityRoles =
716
| {
817
accessibilityRole:

0 commit comments

Comments
 (0)