Skip to content

Commit 2f8a86f

Browse files
authored
fix: changed accessibility label based on onPress callback (#3719)
1 parent 49bdf46 commit 2f8a86f

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/components/Appbar/AppbarContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const AppbarContent = ({
130130

131131
return (
132132
<TouchableWithoutFeedback
133-
accessibilityRole="button"
133+
accessibilityRole={onPress ? 'button' : 'text'}
134134
onPress={onPress}
135135
disabled={!onPress}
136136
>

src/components/__tests__/Appbar/Appbar.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,29 @@ describe('renderAppbarContent', () => {
210210
expect.arrayContaining([expect.objectContaining(v2Spacing)])
211211
);
212212
});
213+
214+
it('Is recognized as a header when no onPress callback has been pressed', () => {
215+
const { getByRole } = render(
216+
<mockSafeAreaContext.SafeAreaProvider>
217+
<Appbar.Header>
218+
<Appbar.Content title="Accessible test" />
219+
</Appbar.Header>
220+
</mockSafeAreaContext.SafeAreaProvider>
221+
);
222+
223+
expect(getByRole('text')).toBeTruthy();
224+
});
225+
it('Is recognized as a button when onPress callback has been pressed', () => {
226+
const { getByRole } = render(
227+
<mockSafeAreaContext.SafeAreaProvider>
228+
<Appbar.Header>
229+
<Appbar.Content title="Accessible test" onPress={() => {}} />
230+
</Appbar.Header>
231+
</mockSafeAreaContext.SafeAreaProvider>
232+
);
233+
234+
expect(getByRole('button')).toBeTruthy();
235+
});
213236
});
214237

215238
describe('AppbarAction', () => {

src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
700700
</View>
701701
</View>
702702
<View
703-
accessibilityRole="button"
703+
accessibilityRole="text"
704704
accessibilityState={
705705
Object {
706706
"disabled": true,

0 commit comments

Comments
 (0)