Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add prop accessibilityState for Menu.Item #3724

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
});
});