Skip to content

Commit 0249f37

Browse files
authored
feat: add prop accessibilityState for Menu.Item (#3724)
Co-authored-by: Bruno Castro <[email protected]>
1 parent 9125545 commit 0249f37

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/components/Menu/MenuItem.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import {
3+
AccessibilityState,
34
GestureResponderEvent,
45
StyleProp,
56
StyleSheet,
@@ -69,6 +70,10 @@ export type Props = {
6970
* Accessibility label for the Touchable. This is read by the screen reader when the user taps the component.
7071
*/
7172
accessibilityLabel?: string;
73+
/**
74+
* Accessibility state for the Touchable. This is read by the screen reader when the user taps the component.
75+
*/
76+
accessibilityState?: AccessibilityState;
7277
};
7378

7479
/**
@@ -111,6 +116,7 @@ const MenuItem = ({
111116
testID,
112117
titleStyle,
113118
accessibilityLabel,
119+
accessibilityState,
114120
theme: themeOverrides,
115121
}: Props) => {
116122
const theme = useInternalTheme(themeOverrides);
@@ -138,6 +144,8 @@ const MenuItem = ({
138144
...(isV3 ? theme.fonts.bodyLarge : {}),
139145
};
140146

147+
const newAccessibilityState = { ...accessibilityState, disabled };
148+
141149
return (
142150
<TouchableRipple
143151
style={[
@@ -151,7 +159,7 @@ const MenuItem = ({
151159
testID={testID}
152160
accessibilityLabel={accessibilityLabel}
153161
accessibilityRole="menuitem"
154-
accessibilityState={{ disabled }}
162+
accessibilityState={newAccessibilityState}
155163
underlayColor={underlayColor}
156164
>
157165
<View style={styles.row}>

src/components/__tests__/MenuItem.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22

3+
import { render } from '@testing-library/react-native';
34
import color from 'color';
45
import renderer from 'react-test-renderer';
56

@@ -170,3 +171,17 @@ it('renders menu item', () => {
170171

171172
expect(tree).toMatchSnapshot();
172173
});
174+
175+
it('accepts different values for accessibilityState', () => {
176+
const { getByTestId } = render(
177+
<Menu.Item
178+
accessibilityState={{ checked: true }}
179+
title="Option 1"
180+
testID="touchable"
181+
/>
182+
);
183+
184+
expect(getByTestId('touchable').props.accessibilityState).toMatchObject({
185+
checked: true,
186+
});
187+
});

0 commit comments

Comments
 (0)