Skip to content

Commit

Permalink
fix: changed accessibility label based on onPress callback (#3719)
Browse files Browse the repository at this point in the history
  • Loading branch information
barttom authored Mar 6, 2023
1 parent 49bdf46 commit 2f8a86f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Appbar/AppbarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const AppbarContent = ({

return (
<TouchableWithoutFeedback
accessibilityRole="button"
accessibilityRole={onPress ? 'button' : 'text'}
onPress={onPress}
disabled={!onPress}
>
Expand Down
23 changes: 23 additions & 0 deletions src/components/__tests__/Appbar/Appbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,29 @@ describe('renderAppbarContent', () => {
expect.arrayContaining([expect.objectContaining(v2Spacing)])
);
});

it('Is recognized as a header when no onPress callback has been pressed', () => {
const { getByRole } = render(
<mockSafeAreaContext.SafeAreaProvider>
<Appbar.Header>
<Appbar.Content title="Accessible test" />
</Appbar.Header>
</mockSafeAreaContext.SafeAreaProvider>
);

expect(getByRole('text')).toBeTruthy();
});
it('Is recognized as a button when onPress callback has been pressed', () => {
const { getByRole } = render(
<mockSafeAreaContext.SafeAreaProvider>
<Appbar.Header>
<Appbar.Content title="Accessible test" onPress={() => {}} />
</Appbar.Header>
</mockSafeAreaContext.SafeAreaProvider>
);

expect(getByRole('button')).toBeTruthy();
});
});

describe('AppbarAction', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
</View>
</View>
<View
accessibilityRole="button"
accessibilityRole="text"
accessibilityState={
Object {
"disabled": true,
Expand Down

0 comments on commit 2f8a86f

Please sign in to comment.