Skip to content

Commit

Permalink
feat: add prop accessibilityState for Menu.Item (#3724)
Browse files Browse the repository at this point in the history
Co-authored-by: Bruno Castro <6487206+brunohkbx@users.noreply.github.com>
  • Loading branch information
brunohkbx and brunohkbx authored Mar 6, 2023
1 parent 9125545 commit 0249f37
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import {
AccessibilityState,
GestureResponderEvent,
StyleProp,
StyleSheet,
Expand Down Expand Up @@ -69,6 +70,10 @@ export type Props = {
* Accessibility label for the Touchable. This is read by the screen reader when the user taps the component.
*/
accessibilityLabel?: string;
/**
* Accessibility state for the Touchable. This is read by the screen reader when the user taps the component.
*/
accessibilityState?: AccessibilityState;
};

/**
Expand Down Expand Up @@ -111,6 +116,7 @@ const MenuItem = ({
testID,
titleStyle,
accessibilityLabel,
accessibilityState,
theme: themeOverrides,
}: Props) => {
const theme = useInternalTheme(themeOverrides);
Expand Down Expand Up @@ -138,6 +144,8 @@ const MenuItem = ({
...(isV3 ? theme.fonts.bodyLarge : {}),
};

const newAccessibilityState = { ...accessibilityState, disabled };

return (
<TouchableRipple
style={[
Expand All @@ -151,7 +159,7 @@ const MenuItem = ({
testID={testID}
accessibilityLabel={accessibilityLabel}
accessibilityRole="menuitem"
accessibilityState={{ disabled }}
accessibilityState={newAccessibilityState}
underlayColor={underlayColor}
>
<View style={styles.row}>
Expand Down
15 changes: 15 additions & 0 deletions src/components/__tests__/MenuItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';

import { render } from '@testing-library/react-native';
import color from 'color';
import renderer from 'react-test-renderer';

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

expect(tree).toMatchSnapshot();
});

it('accepts different values for accessibilityState', () => {
const { getByTestId } = render(
<Menu.Item
accessibilityState={{ checked: true }}
title="Option 1"
testID="touchable"
/>
);

expect(getByTestId('touchable').props.accessibilityState).toMatchObject({
checked: true,
});
});

0 comments on commit 0249f37

Please sign in to comment.